1

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?

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
John Bear
  • 19
  • 1
  • 1
  • 2

1 Answers1

2

You can cast your number to a string,

my_dict = {'1': 3, '2': 7, '3': 14}

number = 2
print(my_dict[str(number)])
ilent2
  • 5,171
  • 3
  • 21
  • 30