I just found a now deleted question on Stack Overflow and solved the problem. The OP was asking for a way to get all the values contained by all 'PLU' keys. I solved it this way but because I am a newbie in python I was wondering if it would be an optimal/better way of doing this, maybe using iterators, I don't know.
Result should be:
234
32
33
334
61
def getPLU(data):
for item in data:
if type(data[item]) == dict:
getPLU(data[item])
else :
if item == 'PLU':
print (data[item])
pass
def Main():
times = 0
Menu = {
'PLU' : '234',
'Salad': {
'salad': {
'ceaser':{
'PLU': '32'
},
'italian':{
'PLU': '33'
}
}
},
'Dessert': {
'cookie': {
'PLU': '334',
'NAME': 'cookie ',
}
},
'Appetizer': {
'extra sauce': {
'PLU': '61',
'NAME': 'extra sauce',
}
}
}
getPLU(data=Menu)
#print (getPLU(Menu))
if __name__ == '__main__':
Main()