Why is dictionary.keys() a list and not a set?
bonono at gmail.com
bonono at gmail.com
Thu Nov 24 04:13:46 EST 2005
Fredrik Lundh wrote:
> Consider a dictionary with one million items. The following operations
>
> k = d.keys()
> v = d.values()
>
> creates two list objects, while
>
> i = d.items()
>
> creates just over one million objects. In your "equivalent" example,
> you're calling d.items() twice to produce two million objects, none
> of which you really care about.
This is what I get from the doc :
a.items() a copy of a's list of (key, value) pairs (3)
a.keys() a copy of a's list of keys (3)
a.values() a copy of a's list of values
I can't derive what you mean by "two list objects" vs "million
objects".
More information about the Python-list
mailing list