+ 1

Fetching key value in dictionary! Why in dictionary keys 1 and True are same

pairs = {1: "apple", "orange": [2, 3, 4], True: False, 2: "True", } print(pairs.get("orange")) print(pairs.get(7)) print(pairs.get(1)) print(pairs.get(2)) Why third print is not fetching key value "apple" While fourth p is getting output

24th Jun 2021, 9:35 AM
Zahed Shaikh
Zahed Shaikh - avatar
5 Answers
+ 3
So I learned that if dictionary contains 1 and True as key then it will work as 1== True Else dictionary containing only 1 as key fetches it's value
24th Jun 2021, 1:24 PM
Zahed Shaikh
Zahed Shaikh - avatar
+ 5
The dictionary contains 1 and True. As True equals 1 as key, True: False over writes 1: "apple". That's why get(1) returns False.
24th Jun 2021, 10:40 AM
Lisa
Lisa - avatar
+ 3
Here is a similar question with answers: https://www.sololearn.com/Discuss/2760597/?ref=app
24th Jun 2021, 10:55 AM
Lisa
Lisa - avatar
+ 1
Zahed Shaikh True means 1 so True == 1 will return True Actually you are doing pairs.get(1) = pairs.get(True)
24th Jun 2021, 1:15 PM
A͢J
A͢J - avatar
0
Why is that keys 1 and True are same in dictionary
24th Jun 2021, 10:49 AM
Zahed Shaikh
Zahed Shaikh - avatar