Retrieving multiple list elements

My 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]

fb_rating_data = [row_1[0], row_1[3], row_1[-1]]
insta_rating_data = [row_2[0], row_2[3], row_2[4]]
pandora_rating_data = [row_5[0], row_5[3], row_5[4]]


avg_rating = (fb_rating_data[2] + insta_rating_data[2] + pandora_rating_data[2]) / 3                                        

What I expected to happen:
why is the number 2 in the brackets following the last line of code? what does the number represnt?:

fb_rating_data[2] + insta_rating_rating[2] + pandora_rating_data[2]

Also, why is there a negative -1 being used as a index then its switched up to a 4? i know they represent the same list item but it is quite confusing

If you look what does the list 'fb_rating_data` or that of insta and pandora represents, and start counting the index from 0, you will know what is happening.

And yes -1 and 4 are the same in this case. Maybe represented to give a better understanding.

2 represent index of the list. Index start with zero (0) so 2 in fb_rating_data[2] means third item of the list fb_rating_data likewise for insta_rating_data[2] and pandora_rating_data[2]

Negative indexing start from right side. so -1 would be last item of list. -2 is second last…

So here row_1[-1] is same as row_1[4]

I understand the concept but when i count the list, ‘USD’ is 2. I don’t see how those are 'fb_rating_data" and the rest are 2. i dont see them in a list in the instructions besides being the variable.

Thanks for responding!

I hope it help you to visualize it. I just marked arrow which item has which value for fb_rating_data.

3 Likes