Another dict method...

Tim Peters tim.one at home.com
Sat May 19 04:33:02 CEST 2001


[Magnus Lie Hetland]
> Anyone who sees the use of a dict.peekitem() which works
> like dict.popitem() but doesn't actually remove an item
> from the dictionary? Could be useful for things like
> this (cf. earlier post about minimum of dict):
> ...
> Just a thought. The following seems a bit ... odd:
>
>     k1, v1 = dict.popitem() # Get an item
>     dict[k1] = v1           # Put it back

Under current CVS Python you can do

    k1, v1 = dict.iteritems().next()





More information about the Python-list mailing list