0

This is my program.I can not print key 1 and lenght is showing 3 .What is the problem.

pairs = {
    1: "apple",
    "orange": [2,3,4],
    True : False,
    12: "True",
    } 
#key Call 
print(pairs[1])

#Dictionary len() check
print(len(pairs))

The output I am getting .Please help anyone.

False
3
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91

2 Answers2

0

Because true is 1 for python. When you assign false to True, it means you assign false to 1.

On the other hand, the keys must be unique in the dictionary. So when you assign multiple value to one key, just one of them will remain.

In your situation, the "apple" replaced with “False”

0

I think it happened because 1 means true and you have overwritten the value of 1 (which was 'apple' before) in the dictionary with false.

also, you can visit this link for more details.