DanielStutzbach / blist

A list-like type with better asymptotic performance and similar performance on small lists
Other
310 stars 36 forks source link

Appending to a list during iteration behaves differently than list() #4

Open DanielStutzbach opened 14 years ago

DanielStutzbach commented 14 years ago

Modifying a list during iteration is undefined by the Python documentation and generally inadvisable. Some people (including the 2to3 tool) rely on CPython's behavior for appending during iteration.

x = list(range(10))
for i in x:
    if i > 100: break
    x.append(i+1)
print len(x)

A regular python list prints 939. With a blist, it prints 39 (as of blist 1.0.2).