Looking for info on Python's memory allocation
Fredrik Lundh
fredrik at pythonware.com
Tue Oct 11 14:37:36 EDT 2005
Alex Martelli wrote:
> (there is no common Python type on which you can both call
> len(...) AND the .next() method, for example -- a combination
> which really makes no sense).
>>> L = [1, 2, 3]
>>> len(L)
3
>>> I = iter(L)
>>> I
<listiterator object at 0x0091ABD0>
>>> len(I)
3
>>> I.next()
1
>>> len(I)
2
>>> I.next()
2
>>> len(I)
1
>>> I.next()
3
>>> len(I)
0
>>> I.next()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
StopIteration
(it's probably not a good idea to rely on this behaviour...)
</F>
More information about the Python-list
mailing list