Conversation
apradoada
left a comment
There was a problem hiding this comment.
GREEN! Overall, Neema, I love how detailed your code is and how easy it is to see your thought process. With that in mind, there are definitely some places where you can cut down on your code and just streamline it a bit! Also, feel free to work on using your helper functions to your advantage!
| # Assert | ||
| assert len(updated_data["watchlist"]) == 0 | ||
| assert len(updated_data["watched"]) == 1 | ||
| assert updated_data['watched']==[{'title': 'It Came from the Stack Trace', 'genre': 'Horror', 'rating': 3.5}] |
There was a problem hiding this comment.
This assert is definitely on the right track, but in an instance like this, it is best practice to use constants in your assert as opposed to hard coded values. This would mean replacing 'It Came from the Stack Trace' with MOVIE_TITLE_1, 'Horror' with GENRE_1 and 3.5 with RATING_1.
| # Assert | ||
| assert len(updated_data["watchlist"]) == 1 | ||
| assert len(updated_data["watched"]) == 2 | ||
| assert updated_data["watched"] ==[{'title': 'The Lord of the Functions: The Two Parameters', 'genre': 'Fantasy', 'rating': 4.0}, {'title': 'It Came from the Stack Trace', 'genre': 'Horror', 'rating': 3.5}] |
There was a problem hiding this comment.
Same kind of deal as the earlier test. An easier way to approach this would be to simply make sure the movie we're moving from "watchlist" to "watched" is actually in the list. That assert would be as follows:
assert movie_to_watch in updated_data["watched"]
| assert movie_to_watch not in updated_data["watchlist"] | ||
| assert movie_to_watch not in updated_data["watched"] | ||
| assert updated_data['watchlist']==[{'title': 'The Lord of the Functions: The Fellowship of the Function', 'genre': 'Fantasy', 'rating': 4.8}] | ||
| assert updated_data['watched']==[{'title': 'The Lord of the Functions: The Two Parameters', 'genre': 'Fantasy', 'rating': 4.0}] No newline at end of file |
There was a problem hiding this comment.
Once again, rather than rewriting the entire dictionary, we can simply use the constants that we have had before!
| assert len(friends_unique_movies) == 3 | ||
| assert INTRIGUE_3 in friends_unique_movies | ||
| assert HORROR_1 in friends_unique_movies | ||
| assert FANTASY_4 in friends_unique_movies |
| # Assert | ||
| assert len(recommendations) == 0 | ||
|
|
||
| #raise Exception("Test needs to be completed.") |
| #create list of all hosts that are available (all_available_hosts) | ||
| all_available_hosts=[] | ||
| for host in user_data["subscriptions"]: | ||
| all_available_hosts.append(host) |
There was a problem hiding this comment.
Once again, you're creating a list (all_available_hosts) that already exists (user_data["subscriptions"]). That would make sense if we were modifying the list in some way, but since we are just walking through the list later, the extra list becomes redundant. You could also simply do the following and you would achieve the same result without the for loop:
all_available_hosts = user_data["subscriptions"]
| if movie_to_recommend in friends_unique_watched: | ||
| recommended_movie_list.append(movie_to_recommend) | ||
|
|
||
| return recommended_movie_list |
| fav_genre=get_most_watched_genre(user_data) | ||
|
|
||
| #call get_friends_unique_watched(user_data) to check conditions for recommendation_list | ||
| friends_unique_watched=get_friends_unique_watched(user_data) |
There was a problem hiding this comment.
This is a great use of the helper functions as well!
| if movie['genre']==fav_genre: | ||
| rec_movie_list_by_genre.append(movie) | ||
| return rec_movie_list_by_genre | ||
|
|
| movies_friends_have_watched=[] | ||
| for friend in user_data['friends']: | ||
| for movie in friend['watched']: | ||
| movies_friends_have_watched.append(movie) |
I am interested about how I could or should have used helper functions in this project.