[Tutor] Dictionaries

Victor Bouffier victor at grupocdm.com
Sun Jan 29 20:31:46 CET 2006

On Fri, 2006-01-27 at 13:20 -0500, Kent Johnson wrote:

> It doesn't make much difference for small dictionaries. keys(), values() 
> and items() create new lists with the specified elements. iterkeys(), 
> itervalues() and iteritems() create iterators that return the specified 
> elements in sequence. So for the common case of iterating over dict 
> elements with a for loop, the 'iter' variants conserve memory and may be 
> faster (but always check!) because of the cost of creating the list.
> The iter variants are relatively new (since Python 2.2). I used to use 
> the older variants in examples here so I wouldn't have to explain the 
> difference :-) but ISTM that modern usage is heading to prefer the iter 
> versions and I am starting to use them myself.
> But I guess you will not notice any difference in performance until you 
> have dicts with many thousands of elements.
> Kent

Hi Kent and Alan,
Thanks to both for your response.

More information about the Tutor mailing list