To collect the values of an api, I use three loopings, I would like to know if it is possible to improve this method that I use.
a = 9625897
def graph(a):
url = f'https://api.sofascore.com/api/v1/event/{a}/graph'
response = requests.get(url, headers=headers, timeout=1).json()
if 'graphPoints' in response:
minutes_list = [d['minute'] for d in response['graphPoints'][-5:]]
value_list = [d['value'] for d in response['graphPoints'][-5:]]
sum_list = sum(abs(d['value']) for d in response['graphPoints'][-5:])
else:
minutes_list = ['graph_error']
value_list = ['graph_error']
sum_list = ['graph_error']
return [minutes_list,value_list,sum_list]