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

dmitrey dmitrey.kroshko at scipy.org
Tue Aug 11 21:31:27 CEST 2009


Yes, thank you, items() is the correct approach, on the other hand I
have already get rid of the cycle.
Regards, D.

On Aug 11, 10:26 pm, "Rami Chowdhury" <rami.chowdh... at gmail.com>
wrote:
> 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.kros... 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