0

Python - I'm beginner. I want to use input() to call one of possible dictionaries (in my example there are: NN and NN1) and then run functions on that chosen dictionary. Here is part of my code (I need this "tik = i" later, but now it does not matter):

NN = {"short name1": "full name1", "short name2": "full name2", "short name3": "full name3"}

NN2 = {"short name4": "full name4", "short name5": "full name5", "short name6": "full name6"}

dict1 = input ("your choice: NN / NN1? ")

for i, j in dict1.items(): 

    tik = i 

    print(j)

When I run it, there is:

"for i, j in dict1.items(): AttributeError: 'str' object has no attribute 'items' "

Is it possible to use input function or do I need sth?

eshirvana
  • 23,227
  • 3
  • 22
  • 38

1 Answers1

-2

you need these changes in your code:

inp_dict = {'NN':NN , 'NN1':NN2}
dict1 = input ("your choice: NN / NN1? ")
for i, j in inp_dict[dict1].items():
    tik = i
    print(j)
eshirvana
  • 23,227
  • 3
  • 22
  • 38