Screen Link: https://app.dataquest.io/m/312/lists-and-for-loops/6/list-of-lists
While I understand the following code
‘’'row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]
row_2 = [‘Instagram’, 0.0, ‘USD’, 2161558, 4.5]
row_3 = [‘Clash of Clans’, 0.0, ‘USD’, 2130805, 4.5]
row_4 = [‘Temple Run’, 0.0, ‘USD’, 1724546, 4.5]
row_5 = [‘Pandora - Music & Radio’, 0.0, ‘USD’, 1126879, 4.0]
app_data_set = [row_1, row_2, row_3, row_4, row_5]
avg_rating = (app_data_set[0][-1] + app_data_set[1][-1] + app_data_set[2][-1] + app_data_set[3][-1] + app_data_set[4][-1]) / 5
avg_rating’’’
I was hoping to do it in one less line of code:
‘’’ avg_rating = ([row_1, row_2, row_3, row_4, row_5] / 5 ‘’’
and received an incompatibility error regarding types: lists and ints.
so, I tried to cast the list as an int, but that failed as well. Is this possible and I’m not seeing the correct syntax or does this need to be a two step procedure in setting a variable, then performing the calculation on the variable. Thank you!
Respectfully,
jw