Guided project 1/ REVIEWS_MAX

Hello, everyone! Could someone, please, explain why we update n_reviews if reviews_max[name] is LESS than n_reviews? This is in line 4, ( if name in reviews_max and reviews_max[name] < n_reviews:). Aren’t we supposed to extract the app with the greatest(max) number of reviews? Shouldn’t it be the greater than instead of less than?

Let’s assume in first iteration we have instagram which is not in dictionary, so we add the app and its number of reviews. In second iteration let`s say we have another instagram but with less reviews compared to the previous one. Why should we update the review with this instagram from second iteration. I mean shouldn’t we skip it if it has less reviews.

I know that less sign is working for the code, and I cannot understand why. I would appreciate if you could explain. Searched in internet, but could not find the satisfied answer.

reviews_max = {}

for app in android:
name = app[0]
n_reviews = float(app[3])

if name in reviews_max and reviews_max[name] < n_reviews:
    reviews_max[name] = n_reviews

elif name not in reviews_max:
    reviews_max[name] = n_reviews

hi @adilbek.aizhan09

I think your problem is that you don’t understand what happens in the loop, I’m going to try to clarify it for you

If you see in line 3 we save the value of the reviews (for the first app in the dataset) in the n_reviews variable, then in the conditional we take the name and number of reviews for the next app and compare it with the one we save before. If the number of reviews is less than the first one we save it in the reviews_max dictionary (which maybe should be named differently) but if the value is bigger then we save that value in n_reviews and then we test the next values against this. So at the end of the entire loop n_reviews is going to have the biggest value in the dataset

Hope this helps you