I have a dict whose keys are numbers. It looks like this:
{'1': 3, '2': 7, '3', 14}
I need to access the value of each key with a variable, but get stuck because of the quotation marks of keys. How can I do that?
I have a dict whose keys are numbers. It looks like this:
{'1': 3, '2': 7, '3', 14}
I need to access the value of each key with a variable, but get stuck because of the quotation marks of keys. How can I do that?
You can cast your number to a string,
my_dict = {'1': 3, '2': 7, '3': 14}
number = 2
print(my_dict[str(number)])