+ 3

Do dictionaries call from 1 or 0 like list?

Dictionaries and lists.

12th Sep 2016, 12:05 PM
Lionell Richards
Lionell Richards - avatar
3 Respostas
+ 5
You don't access to dictionnary values via an index number like with lists. Instead, you use the key to the value. ages = {"Dave": 24, "Mary": 42, "John": 58} print(ages["Dave"])
12th Sep 2016, 12:15 PM
Zen
Zen - avatar
+ 1
Internally but not normally (so: no). It's because they're unordered (by design) and you can 'emulate' the feature by using numeric keys. Abnormally: Trying to get at the 'real' index is potentially confusing, probably neither portable nor repeatable and may surprise others unless you're debugging/testing python (the package) itself.
22nd Sep 2016, 7:31 PM
Kirk Schafer
Kirk Schafer - avatar
0
no you can not access dictionary values using 1,2 like list. it can be accessed through keys.
22nd Sep 2016, 2:54 PM
Sumit Patidar
Sumit Patidar - avatar