I am iterating over a list of tuples in Python
, and it seems to me that the middle element is being skipped somehow. Here is my block of code, with the goal to remove any tuples that have None
as the second element:
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))
And here is the output:
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)]
So...what is happening to the middle (2nd) element? It looks as though it isnt being iterated over at all, or it would print between the other two tuples.