Conversation
| new_movie["genre"] = genre | ||
| new_movie["rating"] = rating | ||
| return new_movie | ||
|
|
There was a problem hiding this comment.
Well done! Just to condense this code slightly, you could just create the movie dictionary within the if statement or even simply return it as a dictionary:
return {"title" : title,
"genre" : genre,
"rating" : rating}
| user_data["watched"].append(movie) | ||
|
|
||
| return user_data | ||
|
|
There was a problem hiding this comment.
Awesome! These extra line breaks aren't necessary for a function this small, but they won't cause any issues.
apradoada
left a comment
There was a problem hiding this comment.
Overall, great job, Reyna! As mentioned throughout the comments, there are a few places where the spacing could be a little more consistent and a few places where you could have condensed some code. Other than that, well done! GREEN!
| def add_to_watchlist(user_data, movie): | ||
| user_data["watchlist"].append(movie) | ||
|
|
||
| return user_data |
| for movie in user_data["watchlist"]: | ||
| if movie["title"] == title: | ||
| user_data["watchlist"].remove(movie) | ||
| user_data["watched"].append(movie) |
There was a problem hiding this comment.
An alternative here to help you get in the practice of using helper methods would be to use the add_to_watched function you created before!
add_to_watched(user_data, movie)
| if movie["title"] == title: | ||
| user_data["watchlist"].remove(movie) | ||
| user_data["watched"].append(movie) | ||
|
|
There was a problem hiding this comment.
You could also put a second return statement here within the if statement. That will allow the for loop to break as soon as it finds the movie it's looking for. This isn't crucial, but it can definitely save some time/space if our data set is large.
| rating_average += movie["rating"] | ||
|
|
||
| return rating_average / len(user_data["watched"]) | ||
|
|
There was a problem hiding this comment.
Just a few notes here. Notice that you do use user_data["watched"] quite a bit here. To save us some trouble, we could simply make a variable that holds that list and use it instead. Also, as a general rule, we don't need to add in the line break right after an if statement definition just because it makes it easier to see what code is part of the if block (Line 41).
| popular_genre[genre] = 1 | ||
| else: | ||
| popular_genre[genre] += 1 | ||
|
|
There was a problem hiding this comment.
We could split these into two separate functions. One that finds the frequency of each genre and one that finds the one that appears most frequently!
| assert len(updated_data["watched"]) == 1 | ||
|
|
||
| raise Exception("Test needs to be completed.") | ||
| assert MOVIE_TITLE_1 == updated_data["watched"][0]["title"] |
There was a problem hiding this comment.
Typically, we'll place the value we are testing on the left and the constant on the right!
|
|
||
| raise Exception("Test needs to be completed.") | ||
| assert MOVIE_TITLE_1 == updated_data["watched"][0]["title"] | ||
| # raise Exception("Test needs to be completed.") |
There was a problem hiding this comment.
Just to be safe, we may want to test our "genre" and "rating" at the same time to make sure the entire movie was brought in correctly!
| # ******************************************************************************************* | ||
|
|
||
| @pytest.mark.skip() | ||
| assert movie_to_watch in updated_data["watched"] |
| assert FANTASY_4 in friends_unique_movies | ||
| assert HORROR_1 in friends_unique_movies | ||
| assert INTRIGUE_3 in friends_unique_movies | ||
| # @pytest.mark.skip() |
| recommendations = get_new_rec_by_genre(sonyas_data) | ||
|
|
||
| # Assert | ||
| assert recommendations == [] |
it's time to party