Kunzite - Celina B and Diana S#67
Conversation
…passing all but Ada-C19#9, Celina's implementation (commented out) passing all but Ada-C19#9 and Ada-C19#10
spitsfire
left a comment
There was a problem hiding this comment.
Good going, Celina and Diana! I've left suggestions and feedback below in your code.
Some things to consider:
- Make sure your variables are descriptive so that anyone reading your code will immediately understand what the function or code block is trying to accomplish
- Use
get_most_watched_genreto help completeget_new_rec_by_genre
| movie = {} | ||
| if not title or not genre or not rating: | ||
| return None | ||
| else: | ||
| movie.update({"title" : title, "genre" : genre, "rating" : rating}) | ||
| return movie |
There was a problem hiding this comment.
Good job on the guard clause! Let's move it to the top, though. That way we aren't creating data in memory that will be immediately tossed if the function hits lines 7-8.
Let's also bring the main focus of the function (creating a movie and returning it) outside a code block.
if not title or not genre or not rating:
return None
movie = {"title" : title, "genre" : genre, "rating" : rating}
return movie| user_data["watched"].append(movie) | ||
| return user_data |
There was a problem hiding this comment.
Consider validating our inputs first to check that movie and/or user_data is what we think it is:
if movie:
user_data["watched"].append(movie)It's small and not necessarily important when passing these tests, but we never want to assume that a user will use our functions correctly.
| user_data["watchlist"].append(movie) | ||
| return user_data |
There was a problem hiding this comment.
Same as above! Let's check input validity!
| return user_data | ||
|
|
||
| def watch_movie(user_data, title): | ||
| print(user_data) |
There was a problem hiding this comment.
Always remember to delete any print statements for debugging purposes when submitting a finale project!
| print(user_data) |
| def watch_movie(user_data, title): | ||
| print(user_data) | ||
| watchlist_list_of_dict = user_data.get("watchlist") | ||
| print(watchlist_list_of_dict) |
There was a problem hiding this comment.
| print(watchlist_list_of_dict) |
| for i in friends_recommendations_list_of_dict: | ||
| if i.get("genre") == frequently_watched_genre_list: |
There was a problem hiding this comment.
Let's come up with a variable name that's more descriptive than i
There was a problem hiding this comment.
What is frequently_watched_genre_list? Is it the most watched genre type, or is it a list? Can we compare a string to a list? Or, should frequently_watched_genre_list be something else?
What if we call one of our functions to get us the most watched genre type, then use it to compare against our recommendation list?
| assert movie_to_watch not in updated_data["watchlist"] | ||
| assert movie_to_watch in updated_data["watched"] |
| # ******************************************************************************************* | ||
|
|
||
| @pytest.mark.skip() | ||
| assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1 |
| assert INTRIGUE_3 in friends_unique_movies | ||
| assert HORROR_1 in friends_unique_movies | ||
| assert FANTASY_4 in friends_unique_movies |
| highest_genre = None | ||
| highest_count_sofar = 0 | ||
| # loop through most watched dict to update | ||
| for genre, count in most_watched_genre_dict.items(): | ||
| if count > highest_count_sofar: | ||
| highest_count_sofar = count | ||
| highest_genre = genre | ||
| #this better work |
There was a problem hiding this comment.
Solely argument's sake, what's another way we might calculate the highest watched genre with our most_watched_genre_dict dictionary and, say, the max function? In what ways might max help make our function more efficient? Or not?
No description provided.