Conversation
kaidamasaki
left a comment
There was a problem hiding this comment.
Great job!
It looks like you just ran out of time to finish debugging a few things. Overall your code looks pretty solid though!
I did point out a few style things but they're really minor.
Well done!
| """ | ||
| This function takes title, genre and ratings as parameters and returns | ||
| the input arguments as values in a dictionary. | ||
| """ |
| new_movie = {} | ||
| if title and genre and rating: | ||
| new_movie["title"] = title | ||
| new_movie["genre"] = genre | ||
| new_movie["rating"] = rating | ||
| return new_movie |
There was a problem hiding this comment.
I recommend creating dictionaries in place when possible:
| new_movie = {} | |
| if title and genre and rating: | |
| new_movie["title"] = title | |
| new_movie["genre"] = genre | |
| new_movie["rating"] = rating | |
| return new_movie | |
| if title and genre and rating: | |
| return { | |
| "title": title, | |
| "genre": genre, | |
| "rating": rating | |
| } |
| for movie in most_watched: | ||
| genres.append(movie["genre"]) | ||
|
|
||
| return mode(genres) |
| if movie["title"] not in user_watched and movie["host"] in user_data["subscriptions"]: | ||
| recommended_movies.append(movie) |
There was a problem hiding this comment.
You need to also check if the movie is in recommended_movies to avoid inserting the same movie twice.
| if movie not in movies_watched_by_user: | ||
| if movie not in friends_watched_movies: | ||
| if movie["genre"] in get_most_watched_genre(user_data): |
There was a problem hiding this comment.
I'd recommend condensing these into a single compound conditional to avoid so much indentation:
| if movie not in movies_watched_by_user: | |
| if movie not in friends_watched_movies: | |
| if movie["genre"] in get_most_watched_genre(user_data): | |
| if movie not in movies_watched_by_user \ | |
| and movie not in friends_watched_movies \ | |
| and get_most_watched_genre(user_data) # prevent TypeError \ | |
| and movie["genre"] in get_most_watched_genre(user_data) \ | |
| and movie not in recommended_movies: |
This reads more clearly if you're used to reading Python code.
You also have a bug if get_most_watched_genre returns None.
This is where it makes sense to see if the movie is already in recommended_movies.
There was a problem hiding this comment.
And, yeah. These conditions are pretty ugly so breaking things out into different passes of the loop might read more cleanly.
No description provided.