0
Help. Regarding dictionary Get function.
I can print "apple" if I remove/comment True = False statement. But I don't understand how I get False for "apple" with the True: False statement. pairs = { 3: "Orange", 1: "apple", 2: "Mango", True:False } print(pairs.get(3)) #Result: Orange print(pairs.get(1)) #Result: False ??? print(pairs.get(2)) #Result: Mango Would appreciate an explanation. Thanks.
7 Réponses
+ 7
True == 1
so 1: "apple" gets overwritten with True: False
+ 5
keys must be unique.
2 is unique
3 is unique
1 is not unique: 1 == True
+ 2
Keys from dict must be unique,
You already have True: False and 1 is equal to True so that s mean your dictionary is like this finally
pairs = {
3: "Orange",
2:"Mango",
True: False # is the same as 1: False
}
If you get the value of key 1, you have False
+ 1
Lisa Thank you.
+ 1
Lisa Thanks so much. This has cleared my doubts.
+ 1
Harimamy Ravalohery Thanks
0
DJ Bubbly you're welcome 🙂