I am trying to understand how index operator [] works in some cases involving dictionaries.
>>> {'a': 1, 'b':2}[1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 1
However...
>>> {True: 1, False:2, True: 3}[1]
3
What's going on here?
Also, what's with the below?
>>> {True: 1, False:2, True: 3}
{False: 2, True: 3}
Why is {True: 1, False:2, True: 3}" evaluating to "{False: 2, True: 3}"?
When searching for answer, I came across this question, but I couldn't find answers to my questions there.
Thanks.