删除不要用for去删除元素,删除一个元素,列表就变了
def remove_sth_in_list(L,element):
if not isinstance(L,list):
return None
while element in L :
L.remove(element)
print(L)
return L
print(remove_sth_in_list([1,2,1,2,1,2],1))
F:\>python 0.py
[2, 1, 2, 1, 2]
[2, 2, 1, 2]
[2, 2, 2]
[2, 2, 2]
版权声明:本文为xinxin920606原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。