actual python iterators

24

looking_for = iter(when_to_change_the_mode)
current = next(looking_for)
for l in listA:
    do_something(current)
    if l == current:
        current = next(looking_for)

>>> # Measure some strings:
... words = ['cat', 'window', 'defenestrate']
>>> for w in words:
...     print(w, len(w))
...
cat 3
window 6
defenestrate 12

Comments

Submit
0 Comments