Retrieving Multiple list elemets

https://app.dataquest.io/m/312/lists-and-for-loops/4/retrieving-multiple-list-elements

how am I supposed to know to use positive or negative indexing?

in the fb_rating_data , insta_rating_data , and `pandora_rating_data’. Wouldn’t the same number be in the answer for the the name of the app, the rating count, and the user rating

1 Like

Using either positive or negative indexing retrieves the same value:

In our solution we’ve used both to show both techniques, but if you use one or the other consistently your answer will be marked as correct.

I hope this helps,

Thank you

Heres’ my other question, when you count the indexes on the graph from track name 3 lands on price and then 4 (or -1) lands on rating_count am I supposed to skip Price when counting the indexes for some reason?
Apple Store.csv dataquest|689x245](upload://4yHtAjQe7XYy7lKLbjUKV5pAe2e.png)

If you look at the exercise, you’ll see that the lists are defined in the initial code, and don’t use the AppleStore.csv data set.

Why did they write this?
Fb_rating_data[2]
Why did they use 2???
Pls explain in detail and simply

The fb_rating_data list was built by indexing 3 elements - the name, the number of the ratings, and the rating itself. By doing fb_rating_data[2], you’re indexing the 3rd element of the fb_rating_data list, which is where the rating is kept.

1 Like

So we don’t have to index the other elements that we used ? And can we choose to index any of the elements that we used ?

I received an error message “avg_rating is greater than what we expected.”
Can’t I use negative indexing instead of positive indexing?

sum = fb_rating_data[-1] + insta_rating_data[-1] + pandora_rating_data[-1]
avg_rating = sum / 3

1 Like

Hi @SweetLuvOfMine,

You can use negative indexing like this:

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[-1] + insta_rating_data[-1] + pandora_rating_data[-1]) / 3

In your case, either this is due to a platform issue or the values for these lists might be incorrect:

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

Best,
Sahil

1 Like

Thanks Sahil! You’re right. I was using row_3 (‘Clash of Clans’) instead of row_5 (‘Pandora - Music and Radio’).

1 Like