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

Chris Angelico rosuav at gmail.com
Fri Mar 18 17:40:29 EDT 2016


On Sat, Mar 19, 2016 at 8:33 AM, Fillmore <fillmore_remove at hotmail.com> wrote:
> what am I missing? I don't want to iterate over the dictionary.
> I know that there's only one element and I need to retrieve the key

You could try:

>>> next(iter(d))

Is that clean enough for usage?

ChrisA



More information about the Python-list mailing list