Open
Conversation
ameerrah9
reviewed
Oct 6, 2022
ameerrah9
left a comment
There was a problem hiding this comment.
Great job using the suggested refactoring! 🎉
Comment on lines
+36
to
+47
| def watch_movie(user_data, title): | ||
| user_data_copy = user_data.copy() | ||
|
|
||
| title_list = [dicts["title"] for dicts in user_data["watchlist"]] | ||
| title_list.extend(dicts["title"] for dicts in user_data["watched"]) | ||
|
|
||
| if title not in title_list: | ||
| return user_data | ||
| user_data_copy["watched"].append(user_data_copy["watchlist"].copy()) | ||
| user_data_copy["watchlist"].pop() | ||
|
|
||
| return user_data_copy |
There was a problem hiding this comment.
You can simplify this by doing something like this:
def watch_movie(user_data, title):
for movie in user_data["watchlist"]:
if movie["title"] == title:
user_data["watchlist"].remove(movie)
user_data["watched"].append(movie)
return user_data
| # ------------- WAVE 2 -------------------- | ||
| # ----------------------------------------- | ||
| def get_watched_avg_rating(user_data): | ||
| watched_list = get_watched_list(user_data) |
There was a problem hiding this comment.
Nice work using your previous function!
Comment on lines
+4
to
+13
| def get_watched_list(user_data): | ||
| return user_data['watched'] | ||
|
|
||
| def get_friends_watched_list(user_data): | ||
| friends_list = user_data['friends'] | ||
|
|
||
| friends_watch_list = [dicts['watched'] for dicts in friends_list] | ||
| friends_watch_list = [val for sublist in friends_watch_list for val in sublist] | ||
|
|
||
| return list({movie['title']:movie for movie in friends_watch_list}.values()) |
| watched_list = get_watched_list(user_data) | ||
| genre_list = [movie['genre'] for movie in watched_list] | ||
|
|
||
| return max(genre_list, key = genre_list.count) if genre_list else None |
Comment on lines
+80
to
+87
| watched_list = get_watched_list(user_data) | ||
| friends_list = get_friends_watched_list(user_data) | ||
|
|
||
| for movie in watched_list: | ||
| if movie in friends_list: | ||
| friends_list.remove(movie) | ||
|
|
||
| return friends_list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactored party.py for list comprehension and readability