Rebinding overlaps
inside the loop won't have any effect on the loop (though mutating it obviously would). Rebinding subseq_iq in side the loop could affect the generator.
A for
loop evaluates the expression to get an iterator once at the beginning of the loop: in this case the expression is simply the name overlaps
. Once it has evaluated that expression it creates an iterator from the iterable and uses that iterator to work through the elements. The iterator depends on the object returned by the expression, it doesn't depend on the name used to identify that object (if indeed there is any name).
If this particular case the code is exactly equivalent to:
for ssid in overlaps:
if ssid != subseq_id:
overlaps = subseq_id_to_overlap_ssids_dict[ssid]
This is a clearer way to write it, but again rebinding overlaps
doesn't change the sequence being used by for
.