for key, value in dict.<func>() - how to get? (which func)

Rami Chowdhury rami.chowdhury at gmail.com
Tue Aug 11 21:26:05 CEST 2009


Hi Dmitrey,

I think what you're looking for is myDict.items(), or myDict.iteritems().

Cheers,
Rami

On Tue, 11 Aug 2009 12:15:13 -0700, dmitrey <dmitrey.kroshko at scipy.org>  
wrote:

> hi all,
> which method should I use to get iterator over (key, value) pairs for
> Python dict, Python v 2.6 and above?
>
> Of course I could use
>
> for key in myDict.keys():
>     value = myDict.values()
>     # do something with the pair key, value
>
> but searching each time for the value take some cputime that is
> serious for the task involved
>
> IIRC in python 2.5 I have something like keyvalues(), but I don't see
> something like that in current dir(myDict).
>
> Thank you in advance, D.



-- 
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)



More information about the Python-list mailing list