Beginner needs help

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

Hey guys, i am totally new to programming languages. Stumbled upon something i don’t understand and would really appreciate any input.

As you can see the last row in bold, i do not understand what [2] in all rating_data stands for? Can somebody clarify please?

Hi, welcome to the community!

Since the rating_data variables are all lists, we’re accessing the item in the 2nd index of each list in order to calculate the average rating. In the fb_rating_data list, the item at index 2 is row_1[-1], which is the last item in row_1: 3.5. So fb_rating_data[2] is 3.5. If you follow the same reasoning with the other 2 rating_data variables, you find that insta_rating_data[2] is 4.5 and pandora_rating_data[2] is 4.0. These are the 3 numbers being averaged for avg_rating.

Does that help at all?

Hey @jordanminh, welcome to the community!

Here’s your row_1: row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5] which is a python list (indicated by [])
In a Python list, the elements (items present in the list) are 0 indexed and can be selected as list_name[index number]

Here’s how it can be visualized:

So when you write row_1[0], what you are saying is select the 0th index element in row_1 which in this case is 'Facebook'

Now, coming to your question:
avg_rating = (fb_rating_data[2] + insta_rating_data[2] + pandora_rating_data[2]) / 3

I think this image might be of some help!


Hope this helps :slight_smile: