lundi 15 avril 2019

Hard time understanding the use of if + in while creating a new dictionary/list

I don't understand how the code below works. How is it possible to have something "in" reviews_max if it's an empty dictionary?

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

Aucun commentaire:

Enregistrer un commentaire