I try to use but no output:
d = {'a': 1,'b': 2}
value = input()
result = None;
for key in d:
if d.get(key) == value:
print(key)
What's the problem?
And also, what's the difference between d['1']
and d.get('a')
?
I try to use but no output:
d = {'a': 1,'b': 2}
value = input()
result = None;
for key in d:
if d.get(key) == value:
print(key)
What's the problem?
And also, what's the difference between d['1']
and d.get('a')
?
For you first question, the issue is that you don't convert your input to an integer:
value = int(input())
Remember, in Python '1' != 1
.
For your second question, see this duplicate question.