0

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
  • 45,449
  • 17
  • 80
  • 115
John Bear
  • 9
  • 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,003
  • 3
  • 20
  • 30