Kunzite - Gabby Y. and Allie S.#45
Conversation
spitsfire
left a comment
There was a problem hiding this comment.
Great job, Gabby and Allie! Very clean, easy to read code! I've left a few suggestions below, but overall your logic looks good!
|
|
||
| def create_movie(title, genre, rating): | ||
| pass | ||
| if (not title) or (not genre) or (not rating): |
There was a problem hiding this comment.
We only need parentheses around conditional statements when we need multiple conditions to be finished first, then move on to another group. For example, if (not title or not genre) and not rating; otherwise, forgo parentheses. It's not very Pythonic.
| new_movie = {} | ||
| new_movie["title"] = title | ||
| new_movie["genre"] = genre | ||
| new_movie["rating"] = rating |
There was a problem hiding this comment.
This works! We can also do this all at once, too inside new_movie
| return new_movie | ||
|
|
||
|
|
||
| def add_to_watched(user_data, movie): |
| return user_data | ||
|
|
||
|
|
||
| def add_to_watchlist(user_data, movie): |
| # ----------------------------------------- | ||
|
|
||
|
|
||
| def get_watched_avg_rating(user_data): |
| for movie in user_data["watchlist"]: | ||
| if title == movie["title"]: | ||
| move_movie = movie | ||
| user_data["watchlist"].remove(movie) | ||
| user_data["watched"].append(move_movie) |
There was a problem hiding this comment.
Careful here! We are removing items from a list while iterating through it. This can result in items being skipped over because of a shift in index positions.
How best to combat this can depend. We could make a copy of the watchlist and remove from one while we loop through the other. Or perhaps we can break once we finish line 39. But then that begs the question, what if the same movie is inside the list?
Something to think about!
| assert updated_data["watchlist"] == [] | ||
| assert updated_data["watched"] == [{ | ||
| "title": MOVIE_TITLE_1, | ||
| "genre": GENRE_1, | ||
| "rating": RATING_1 | ||
| }] |
| assert updated_data["watchlist"] == [ | ||
| FANTASY_1 | ||
| ] | ||
| assert updated_data["watched"] == [FANTASY_2, movie_to_watch] |
| assert friends_unique_movies == [ | ||
| {'title': 'The Programmer: An Unexpected Stack Trace', | ||
| 'genre': 'Fantasy', 'rating': 4.0}, | ||
| {'title': 'It Came from the Stack Trace', | ||
| 'genre': 'Horror', 'rating': 3.5}, | ||
| {'title': 'Zero Dark Python', 'genre': 'Intrigue', 'rating': 3.0} | ||
| ] |
| recommendations = get_new_rec_by_genre(sonyas_data) | ||
|
|
||
| # Assert | ||
| assert recommendations == [] | ||
| assert len(recommendations) == 0 |
No description provided.