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
unique_apps(android_data)
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))
18
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.