PEP 372 -- Adding an ordered directory to collections

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Jun 18 06:35:06 EDT 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.

Bye,
bearophile



More information about the Python-list mailing list