Looking up a dictionary _key_ by key?

Ben Finney ben+python at benfinney.id.au
Tue Jun 23 20:33:50 EDT 2015


Dan Stromberg <drsalists at gmail.com> writes:

> Is there a way of getting the key used by the dictionary, short of
> storing a reference to it in the value, or using a second dictionary?

The dictionary knows its keys and can provide them on request. Call the
‘dict.keys’ method to get them as a collection.

-- 
 \     “Capitalism has destroyed our belief in any effective power but |
  `\      that of self interest backed by force.” —George Bernard Shaw |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list