[Tutor] Dictionaries

Victor Bouffier victor at grupocdm.com
Fri Jan 27 18:22:33 CET 2006


Hi Alan and Ken,

I think know the difference between using items() vs. iteritems() and
their equivalent for keys and values. I notice Ken suggests iteritems(),
while Alan suggests items() only.

Does one approach have an advantage over the other?
Should we use only one of them favorably?

Thanks.
Victor

On Thu, 2006-01-26 at 13:43 +0000, Alan Gauld wrote:
> > How would I modify this to just print either the values or keys?
> 
> Just ask for the values or the keys!
> 
> for value in pairs.values()
>      print value
> 
> for key in pairs.keys()
>      print key
> 
> for key,value in pairs.items()
>     print key
>     print value
> 




More information about the Tutor mailing list