Python Fundamentals: Guided Project (if-question)

Hi there

I got a question concerning the if-statement:

image

So python loops through the android dataset, and adds let’s say {‘Facebook’: 80000000} to reviews_max dictionary, and short time later it gots replaced by {‘Facebook’: 90000000}, because of the higher review number:

Wouldn’t be the correct way to write it be like this:

if name in reviews_max and reviews_max[name] ">" n_reviews:
reviews_max[name] = n_reviews
So ">" instead of "<"

so the incoming value (reviews_max[name]) has to be bigger than the current (n_reviews) value.

Thank you for any enlightment.

Cheers

1 Like

This is a tricky part! reviews_max[name] is coming from the dictionary as it exists in that moment, not the incoming value. The incoming value is n_reviews because it’s coming from that row in the loop. So we’re asking if the app already exists in the reviews_max dictionary, and if the value already there (reviews_max[name]) is less than the current value n_reviews, then we change the dictionary so that the value is updated.

I hope that helps.

2 Likes

Hey @april.g
Awesome, you are always there when I need help :wink:

Thank you very much!

2 Likes