how to can i go over a file twice?

As others have commented you probably have an iterator, not a list; You can use itertools.tee to get two independent iterators from same iterable:

>>> from itertools import tee
>>> a = [1, 2, 3]
>>> fst, snd = tee(iter(a))  # two copies of same iterator
>>>
>>> list(fst)  # exhaust the first iterator
[1, 2, 3]
>>> list(snd)  # now use the 2nd one
[1, 2, 3]

Leave a Comment