0
Play this code and read output. I asked my question there.
3 Respostas
+ 2
lst = [k for k,v in dic.items() if v == "10"]
print(lst) # ['A']
+ 1
Remember the keys in a dictionary are unique. The values don't have to be.
Using dict.get() works because if the key is there, there will only be one corresponding value. It doesn't work the other way around. E.g.
dicA = {Jim: male, Jane: female, Jack: male, Joe: male}
You can't input "male" and extract just one name, because there are three.
0
Just change line 2 like this:
dic ={"A": "10", "10":"A"}