I have defined two dictionaries dict1
and dict2
. I want the user to tell me via input, which dictionary to access (of course he has to know the exact names), so he gets a value from this dictionary. The following doesn't work out, I get a
Type Error "string indices must be integers":
dict1 = {'size': 38.24, 'rate': 465}
dict2 = {'size': 32.9, 'rate': 459}
name = input('Which dictionary to access?: ')
ret = name['size']
print ('Size of ' + name + ' is ' + str(ret))