dictionaries | SoloLearn: Learn to code for FREE!

+1

dictionaries

this my code fruits={1:"apple","orange":[2,3,4],True:False,None:"true",} print(fruits.get(1)) OUTPUT >> False what's the mistake in code when i replace with 1 with 0. i m getting out put as "apple". somebody help...

5/30/2018 10:32:41 AM

Aju George

2 Answers

New Answer

+4

This is because there are conflicting keys in your dictionnary. This may not be obvious but 1 and True represents the same thing because in Python the boolean True equates the integer 1 and False equates the integer 0. So when you do fruits.get(1) since you have a conflict it gets the latest entry with that key, at least that is what I have seen happen. Run this code to see what I mean. For each list look at the order of the entries and check what the output is. https://code.sololearn.com/c7a6sNRDtNm7/?ref=app

+2

thanku ☺