0
PYTHON - Dictionaries get print(pairs.get(1)) why = True, but 1,2 and 3 not??? Why not output = "apple"
pairs = {1: "apple", 2: "pear", 3: "apricot", True: "True", 4: "potatoe" } print(pairs.get(1)) print(pairs.get(2)) print(pairs.get(3)) print(pairs.get(4)) print("\n") Why is print(pairs.get(1)) Output= True and not apple 2,3,4 are rational outputs but the first output totally confused? Pls reply, Regards, Philip
2 Answers
+ 2
Because 1 and True mean the same thing......keys must be unique and as True is later on in the dict...the 1 is removed...print out the dict to see what I mean.
just do add..... dictionary can be used to remove duplicate elements in the list and is faster than set(). and (I think) the ordering is kept.
0
@rodwynnejones thanks for the info, I've written new code to explain it to myself