+ 1

indexes in dictionaries

I'm sure I've read somewhere you can't index a dictionary the same way you can a list or when you index a range. maybe they just meant the syntax is different. besides that the norm in python is to count from zero, so that raises the question whether when specifically talking about indexes in ranges/dict/list etc. that you start from one. some clarification would be nice

7th Sep 2016, 11:41 PM
Terrance Rafferty
Terrance Rafferty - avatar
3 Respostas
+ 3
With dictionnaries, instead of accessing a value with an index, you use a key. ages = {"Dave":24, "Mary":42, "John":58} print(ages["Dave"])
8th Sep 2016, 12:29 AM
Zen
Zen - avatar
+ 2
If the answer you were looking for is different from the one I gave you, feel free to share.
8th Sep 2016, 12:45 AM
Zen
Zen - avatar
+ 1
I've just done a bunch of testing in playground and researched a bit and it answered my questions. Thankyou for your reply
8th Sep 2016, 12:40 AM
Terrance Rafferty
Terrance Rafferty - avatar