-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingredients.py
31 lines (24 loc) · 975 Bytes
/
ingredients.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
def get_cocktail_ingredients():
strIngredient = list()
strMeasure = list()
with open("json_obj.json") as file:
dict_json = json.load(file) # dict
for key in dict_json["drinks"][0]: # for all values in json
if dict_json["drinks"][0][key] is not None:
if key.startswith("strIngredient"):
strIngredient.append(key)
elif key.startswith("strMeasure"):
strMeasure.append(key)
sum_measure_and_ingredient = list()
# summing 2 values json
for i in range(len(strIngredient)):
try:
sum_measure_and_ingredient.append(
dict_json["drinks"][0][strMeasure[i]]
+ dict_json["drinks"][0][strIngredient[i]]
)
except IndexError:
pass
sum_measure_and_ingredient.append(dict_json["drinks"][0]["strIngredient3"])
return sum_measure_and_ingredient