Message 65752 - Python tracker (original) (raw)

John, when y=[], the update method has to create a new list iterator on each invocation. But when y is a genexp, it is self-iterable (iow, iter (y) will return self, not a new object).

Also, when doing timings, it can be helpful to factor-out the attribute lookup:

python -m timeit -s 'x=set(range(10000)); y=[]; xu=x.update' 'xu(y)'