+ 2
Can we use two or more same keys in a dictionary?
just like joe:24,joe:12,jet:28
4 Respostas
+ 7
yeah
+ 5
Yes you can, but only the last one entered will remain as part of the dictionary,
Take into account the following code:
myDict = {"joe": 23, "joe":55, "ben":34} # first element is is changed to 55 by second
# our dictionary is actually {"joe": 55, "ben":34}
print(myDict["joe"]) # outputs 55 not 23
print(myDict["joe"]) # again outputs 55 not 23
print(myDict["ben"]) # outputs 34
print(len(myDict)) # when checking the length of the dict you get 2 instead of 3
+ 1
Yes use a list...
myDict = {"Bob":[1,2,3]}
you can store multiple values. You can call them by using...
myDict["Bob"][0] # output is 1
+ 1
can list(d.keys()) out put the joe,joe,ben or joe,ben ?