[Tutor] Getting first item in dictionary
David L Neil
PyTutor at DancesWithMice.info
Mon Jan 27 19:22:53 EST 2020
On 28/01/20 8:30 AM, Roel Schroeven wrote:
> S D schreef op 27/01/2020 om 12:51:
>> I have a dictionary which contains one item (“current_location”, which
>> is a
>> nested dict) and I would like to access that nested dict. However, I
>> cannot
>> use the key as the code will break if a different key is passed, e.g.
>> “different_location".
>>
>> How can I access the first item in a dictionary without using a key? The
>> dict looks like this:
...
> That should extract the one item from a dictionary, if there is only
> one. And I think it should extract the first item even if there are
> multiple items, but that "first item" might not be what you expect
> depending on your expectations and the version of Python you use.
v3.7+
"the insertion-order preservation nature of dict objects has been
declared to be an official part of the Python language spec."
https://docs.python.org/3/whatsnew/3.7.html
--
Regards =dn
More information about the Tutor
mailing list