NameError: name 'reviews_max' is not defined

Screen Link:

My Code:
def unique_apps(dataset):

reviews_max = {}

for app in dataset:
        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

print(‘Expected length:’, len(android_data)- 1181)
print(‘Actual length:’, len(reviews_max))

What I expected to happen:
The dictionary reviews_max to be populated with unique app names and their highest number of reviews.

What actually happened: 
I received the name not defined error.

NameErrorTraceback (most recent call last)
in ()
15 unique_apps(android_data)
16 print(‘Expected length:’, len(android_data)- 1181)
—> 17 print(‘Actual length:’, len(reviews_max))

NameError: name ‘reviews_max’ is not defined

<!--Enter other details below: -->
I have tried running the code to generate the dictionary containing the unique app names as the key and the maximum number of reviews as the values. I have been creating my code as functions with no issues, but I have tried running the code directly referencing the android_app dataset as well (android dataset with header removed) - even copied and pasted from the solutions notebook (to ensure no typos). I repeatedly get the same error.

The only difference I am noticing between my code and the solutions notebook (and other samples) is that in the if statement the < is highlighted whenever entered into my code.

I confirmed that the android_data set is properly loaded by printing a sample row from this cell in the notebook.

Please assist.

I would recommend going through the concept of scopes again from this Mission

The reason you get that error is because you have reviews_max defined inside of the function unique_apps. And then you try to access it outside of that function.

reviews_max's scope is limited to that function only, and it can’t be accessed outside of it, since it’s not defined outside of that function. The Mission I shared above should help you understand this better if it’s still unclear.

Resolved. Thank you.