RT
#删除特点位置元素,但不改变远列表的方法
alist = [1,2,3,4,5,1]
for i in range(len(alist) - 1, -1, -1):
blist = []
#复制一份原列表
for j in range(len(alist)):
blist.append(alist[j])
#比较
print(blist)
blist.pop(i)
print(blist)
#判断
if alist[i] in blist:
print("NO")
#分割,便于查看
print("_"*50)
输出结果
[1, 2, 3, 4, 5, 1]
[1, 2, 3, 4, 5]
NO
__________________________________________________
[1, 2, 3, 4, 5, 1]
[1, 2, 3, 4, 1]
__________________________________________________
[1, 2, 3, 4, 5, 1]
[1, 2, 3, 5, 1]
__________________________________________________
[1, 2, 3, 4, 5, 1]
[1, 2, 4, 5, 1]
__________________________________________________
[1, 2, 3, 4, 5, 1]
[1, 3, 4, 5, 1]
__________________________________________________
[1, 2, 3, 4, 5, 1]
[2, 3, 4, 5, 1]
NO
__________________________________________________