PEP 372 -- Adding an ordered directory to collections

bearophileHUGS at bearophileHUGS at
Wed Jun 18 12:35:06 CEST 2008

Martin v. L.:
> However, I think the PEP (author) is misguided in assuming that
> making byindex() a method of odict, you get better performance than
> directly doing .items()[n] - which, as you say, you won't.

In Python 2.5 .items()[n] creates a whole list, and then takes one
item of such list.
An O(n) byindex() just scans the items to return the n-th.
So while being both O(n) in time, the .items()[n] may allocate quite
more memory.


More information about the Python-list mailing list