Dictionary Views -- good examples? [was Re: Python 3 dict question]

Gregory Ewing greg.ewing at canterbury.ac.nz
Sat May 7 05:09:09 EDT 2011


Ethan Furman wrote:
> Ian Kelly wrote:
> 
>> next(iter(myDict.items()))
> 
> Which is becoming less elegant.

If you're doing this sort of thing a lot you can make
a little helper function:

   def first(x):
     return next(iter(x))

then you get to say

   first(myDict.items())

-- 
Greg



More information about the Python-list mailing list