'Python3: How to dynamically reference the name of a dictionary
I'm still learning python and I'd appreciate any direction for the problem that I'm having.
I have menu options set up in two separate dictionaries in the following structure
menu0000 = {
1 : {
"label" : "Library"
},
2 : {
"label" : "Listen Now"
}
}
menu0001 = {
1 : {
"label" : "Shuffle Songs"
},
2 : {
"label" : "Playlists"
}
}
A variable has been set up to keep track of the name of which dictionary I am currently accessing
menuName = "menu0000"
Without hard-coding the name, I'd like to access the dictionary dynamically based on the contents of the menuName variable, eg:
for key in menuName:
print(menuName[key]["label"])
How do I call menuName in a way that invokes a dictionary? The idea is to update menuName at a later stage so that I can access different dictionaries.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
