every time i run it it gives me only the last value of social_score, while I want to get all the social_score values in the json API and store the output to an #iterated list to calculate with the valueI
help on this JSON
url = requests.get("https://api2.lunarcrush.com/v2?data=assets&symbol=xrp&data_points=730&interval=day&change=max").json() def get_data(): for data in url['data']: result = data['social_score'] print(result) get_data()
CodePudding user response:
Store the intermediate results in a list variable:
url = requests.get("https://api2.lunarcrush.com/v2?data=assets&symbol=xrp&data_points=730&interval=day&change=max").json()
def get_data():
results = []
for data in url['data']:
result = data['social_score']
results.append(result)
return results
result = get_data()