我正在遍历 中的元组列表,在Python
我看来,中间元素正在以某种方式被跳过。这是我的代码块,目的是删除所有None
作为第二个元素的元组:
print('List of tuples before modification: ' +str(list_of_tuples))
for refseq_tuple in list_of_tuples:
print('tuple: ' +str(refseq_tuple))
if refseq_tuple[1] == None:
list_of_tuples.remove(refseq_tuple)
print('List of tuples after modification: ' +str(list_of_tuples))
这是输出:
List of tuples before modification: [('100652761', None), ('100653343', None), ('3183', 0)]
tuple: ('100652761', None)
tuple: ('3183', 0)
List of tuples after modification: [('100653343', None), ('3183', 0)]
那么......中间(第二个)元素发生了什么?它看起来好像根本没有被迭代,或者它会在其他两个元组之间打印。