Ocelots - Diana A.#20
Conversation
| GENRE_1 = "Horror" | ||
| RATING_1 = 3.5 | ||
|
|
||
| MOVIE_TITLE_2 = "Ratatouille" |
There was a problem hiding this comment.
Way to go, even adding additional testing data!
|
|
||
| # Assert | ||
| assert len(updated_data["watched"]) == 2 | ||
| assert updated_data["watched"][1]["title"] == MOVIE_TITLE_1 |
There was a problem hiding this comment.
Excellent thoroughness, testing all of the attributes here for completeness
|
|
||
| def create_movie(title, genre, rating): | ||
| pass | ||
| if not bool(title) or not bool(genre) or not bool(rating): |
There was a problem hiding this comment.
Interesting use of casting to bool to cover "" and None
|
|
||
|
|
||
| def watch_movie(user_data, title): | ||
| for movie in user_data["watchlist"]: |
There was a problem hiding this comment.
This is working here, but an important note is that it is generally dangerous practice to modify a data structure that you are using to loop over. This can lead to bugs in more complex code. One alternative could be making a copy of what you get from " movie in user_data["watchlist"]:" so that that collection does not change while you modify user_data["watchlist]" from inside the loop.
|
|
||
| watched_genres = {} | ||
| for movie in user_data["watched"]: | ||
| watched_genres[movie["genre"]] = watched_genres.get(movie["genre"], 0) + 1 |
| def get_unique_watched(user_data): | ||
| watched_movies_list = user_data["watched"] | ||
| friends_watched_movies_list = get_friends_watched_movies(user_data) | ||
| return [movie for movie in watched_movies_list if movie not in friends_watched_movies_list] |
There was a problem hiding this comment.
This is a really clever single line! I would say that in general it's more useful for yourself or other developers to write out the steps, so that it's easier to understand-- and to debug and maintain in the future.
There was a problem hiding this comment.
Also, now that we've had some more experience, can you think about how sets could have been used here, and in similar code in your project?
|
|
||
| def remove_movie_duplicates(friends_watched_movies_list): | ||
| friends_watched_movie_titles = {} | ||
| for movie in friends_watched_movies_list: |
There was a problem hiding this comment.
Similar comments about the dangers of modifying a collection while you are iterating over it
No description provided.