retrieve key of only element in a dictionary (Python 3)

Terry Reedy tjreedy at udel.edu
Fri Mar 18 18:06:23 EDT 2016


On 3/18/2016 5:39 PM, Daniel Wilcox wrote:
> I think you're looking for something like popitem().
>
>>>> d = {'asdf':1}
>>>> d.popitem()[0]
> 'asdf'

Only if he wants the item removed.

-- 
Terry Jan Reedy




More information about the Python-list mailing list