Sept. 23, 2004
5:24 p.m.
Tim Peters wrote:
x = [1] x.extend(-y for y in x)
A simpler way:
x = [1, -1] x.extend(iter(x))
Curiously, this didn't "work" before 2.4 either:
x = [1] x.extend(iter(x)) x [1, 1]
The iterator did see the new elements after the extend call but not during it:
x = [1] i = iter(x) x.extend(x) list(i) [1, 1] x = [1] i = iter(x) x.extend([list(i)]) x [1, [1]]
The reason is that in 2.3 `listextend()` passed the right argument through `PySequence_Fast` which copied it before beggining to extend the list. It's much better now. I mean it! Bugs should be predictable. Infinite loop should never terminate silently. Unless explicitly terminated.