I am trying to do the following operation.
rating = []
for i in result['search_results']:
rating.append(float(i['rating']) if i['rating'] exists else 'NaN')
The API call sometimes does not return this value. How can I do an append if exists logic in Python?
float(i['rating']) if 'rating' in i else 'NaN'