Ocelots class - Nadxelle Hernandez#3
Ocelots class - Nadxelle Hernandez#3nadxelleHernandez wants to merge 17 commits intoada-ac2:masterfrom
Conversation
kelsey-steven-ada
left a comment
There was a problem hiding this comment.
🎉 Congrats on completing your first project at Ada! 🎉 I’ve added some suggestions & questions, let me know if there's anything I can clarify.
| assert type(updated_data["watched"][0]) == dict | ||
| assert updated_data["watched"][0]["title"] == MOVIE_TITLE_1 |
There was a problem hiding this comment.
Nice assertions!
In this case where the test is checking individual keys of a dictionary, I recommend including assertions for all of the relevant keys.
watched_movie = updated_data["watched"][0]
assert watched_movie["title”] == MOVIE_TITLE_1
assert watched_movie["rating"] == RATING_1
assert watched_movie["genre"] == GENRE_1| assert movie_to_watch not in updated_data["watchlist"] | ||
| assert movie_to_watch in updated_data["watched"] |
There was a problem hiding this comment.
Great use of movie_to_watch to confirm the object we set up in the # Arrange step is in the watched list and was removed from watchlist!
| assert FANTASY_4 in friends_unique_movies | ||
| assert HORROR_1 in friends_unique_movies | ||
| assert INTRIGUE_3 in friends_unique_movies |
There was a problem hiding this comment.
Great checks for all the relevant data!
| recomendations = get_new_rec_by_genre(sonyas_data) | ||
|
|
||
| assert len (recomendations) == 0 |
|
|
||
| def create_movie(title, genre, rating): | ||
| pass | ||
| if not title or not genre or not rating: |
There was a problem hiding this comment.
Great use of the truthy/falsy values to check for empty strings or None in one statement!
| if not user_data: | ||
| return None | ||
|
|
||
| return get_not_watched_by_friends(user_data["watched"],user_data["friends"]) |
There was a problem hiding this comment.
This function has 3 statements, and the code in both this function and get_not_watched_by_friends doesn't seem reusable by others. In this situation I would strongly consider if we benefit from a second function.
If we wanted to create a helper function for organization, I might suggest creating one function that performs the first task of creating a list of all of the movies in user_data["friends"]. Then in get_unique_watched we could call that function and use the result to perform the second task of finding movies from user_data["watched"] that are not in our list of friend movies. This organization gives us 2 functions that each have a single purpose, and we could reuse the function to get the list of friend movies in get_friends_unique_watched below.
| friends_watched = get_friends_unique_watched(user_data) | ||
|
|
||
| for movie in friends_watched: | ||
| if movie["host"] in user_data["subscriptions"] and movie not in recomendations: |
There was a problem hiding this comment.
The PEP 8 style guide recommends limiting lines to a max of 79 characters to make code easier to read, especially with multiple editor windows open: https://peps.python.org/pep-0008/#maximum-line-length. We would want to break it over a couple lines or create variables to hold the comparisons that we then use in an if statement:
is_host_in_subscriptions = movie["host"] in user_data["subscriptions"]
is_movie_in_recommendations = movie in recomendations
if is_host_in_subscriptions and not is_movie_in_recommendations:
recomendations.append(movie)| return None | ||
|
|
||
| recomendations = list() | ||
| friends_watched = get_friends_unique_watched(user_data) |
| friends_watched = get_friends_unique_watched(user_data) | ||
|
|
||
| for movie in friends_watched: | ||
| if movie["host"] in user_data["subscriptions"] and movie not in recomendations: |
There was a problem hiding this comment.
Nice algorithm! Another way we could approach filtering the unique_watched list is with a list comprehension:
# list comprehension
result = [movie for movie in friends_watched
if movie["host"] in user_data["subscriptions"]]| if not user_data: | ||
| return None | ||
|
|
||
| return get_not_watched_by_friends(user_data["favorites"],user_data["friends"]) |
There was a problem hiding this comment.
What a cool way to reuse get_not_watched_by_friends 😄
Finished project