Hi community,
I ran into the problem of putting the return of one function into another. Maybe someone could recommend any solution?
Let me describe a situation:
Function 1:
def get_list(*key):
headers_list = {
"Accept": "application/json",
}
getlst = requests.get("https://api.example.com/v3.0/api/Menu/List", headers = headers_list)
getlst_res = getlst.json()
for item in getlst_res:
print(item[key[0]] + ' = ' + item[key[1]])
Usage of the function 1:
get_list('name','code')
Output of the function 1:
2N = 2N
360 = ZW
70MAI = MQ
ARMR = AR
Function 2:
def get_id(*key):
headers_id = {
"Accept": "application/json",
}
pid = requests.get(f"https://api.example.com/v3.0/api/Menu/Items?itemCode={key[0]}", headers = headers_id)
pid_res = pid.json()
for item in pid_res:
print(f'Item id: {item[key[1]]}')
Usage of the function 2:
get_id('2N', 'id')
Output of the function 2:
Item id: 1226569
Item id: 1226571
Item id: 1218108
Item id: 1218111
Item id: 1227409
In the “Output of the function 2” you could see only item ids which were assigned to “code” - “2N”.
Expected result:
In the “Output of the function 1” we get more “codes”: “ZW”, “MQ”, “AR”.
The main goal is to get the item ids of all codes (“2N”, “ZW”, “MQ”, “AR”) as the single output.
(Not only “2N” item ids, but as well “ZW”, “MQ” and “AR”)
Thanks in advance