Python how to "use" the return of a function

Viewed 34

Beginner Question beware

So basically I am using an API to get certain Data, in this case a dealID.

I am using following code:

resp = service.get_deal_data( size=1, level=None, limit_distance=None, limit_level=None)

Size, level etc do not matter.

So the api call returns this output:

{'date': '2022-09-20T13:35:42.042',
 'status': 'OPEN',
 'reason': 'SUCCESS',
 'dealReference': 'MKPYFDNLMCCTYNK',
 'dealId': 'DIAAAAKMH5HGMA8',
 'affectedDeals': [{'dealId': 'DIAAAAKMH5HGMA8', 'status': 'OPENED'}],
 'level': 0.99663,
 'size': 1.0,}

My question is how do I get the data from the output to use it in another function

I want to get the DealID and continue to use it without inputting manually.

F.e.:

I want to compare the deal ID to a list of IDs and return a warning if it already is on the list.

list = [DDHWUH5HGMA8,JNDWJ7HDJ2, 7HDWUDH9D, ...]

if dealId in list:
    print("exist")
else:
    print("not exist")

returns following error:

NameError: name 'dealId' is not defined

1 Answers

If the API result is the type of dictionary, then Try doing :

list = [DDHWUH5HGMA8,JNDWJ7HDJ2, 7HDWUDH9D, ...]

if resp['dealID'] in list:
    print("exist")
else:
    print("not exist")
Related