recipedict = {'sandwich':['a buttered sandwich',[['bread','13'],['butter','4']]]}
supplydict = {'bread':['150','15','james'],'butter':['15','12','allen'],'sugar':['15','12','marc']}
supplierdict = {"james":'12345234',"allen":'17682342'}
for example I have these 3 dictionaries. I need to check if the inner element of the second value of the recipedict is in the supply dict. so check if bread and butter is in the supply dict. If bread and butter is in the supplydict, get the second value of the supplydict, in this case it would be james and allen, and get the first value in supplier dict. then print the associated values with each other
ingredient: bread
amount needed: 13
supplier: james
supplier contact: 12345234
ingredient: butter
amount needed: 4
supplier: allen
supplie contact: 17682342
i tried getting all the lists together but i only print the whole list with the associated dictionary value
def flatten(l):
return [item for sublist in l for item in sublist]
for key, value in recipedict.items():
onevalue = value[1]
#print(onevalue)
actuallist = [item[0] for item in onevalue]
valew = []
for k in actuallist:
if k in supplydict:
valuee = supplydict.get(k)
valew.append(valuee[2])
print(valew)
z = flatten(onevalue)
#print(y)
n = 1
word = valew
for i in range(n, len(onevalue) + n, n + 1):
onevalue.insert(i, word)
print(onevalue)
Try this:
goal = 'sandwich'
for ingredient, needed in recipedict[goal][1]:
_, _, supplier = supplydict[ingredient]
contact = supplierdict[supplier]
print('ingredient', ingredient)
print('amount needed', needed)
print('supplier', supplier)
print('supplier contact', contact)
print()