Conversation
| @@ -0,0 +1,259 @@ | |||
| #Wave_One part 1 | |||
| def create_movie (title, genre, rating): | |||
| return None | ||
|
|
||
| #Wave_One part 2 | ||
| def add_to_watched(user_data, movie): |
|
|
||
| #Wave_One part 3 | ||
|
|
||
| def add_to_watchlist(user_data, movie): |
| if movie["title"] == title: | ||
|
|
||
| user_data["watched"].append(movie) | ||
| user_data["watchlist"].remove(movie) |
There was a problem hiding this comment.
even though remove works great here, be careful using it in a for loop. It can cause side effects. Here is a link that explains it more with examples https://thispointer.com/python-remove-elements-from-a-list-while-iterating/
|
|
||
|
|
|
|
||
| #Wave_TWO Part 1 | ||
|
|
||
| def get_watched_avg_rating(user_data): |
| if "genre" in movie_genre: | ||
| most_populare_genre.append(movie_genre["genre"]) | ||
| most_common = max(most_populare_genre, key = most_populare_genre.count) | ||
| print (most_common) |
| #Completed using a dict but wasn't my first choice | ||
| # def get_most_watched_genre(user_data): | ||
| # most_popular_genre = {} | ||
| # if len(user_data["watched"]) == 0: | ||
| # return None | ||
| # for movie_genre in user_data["watched"]: | ||
| # if movie_genre ["genre"] in most_popular_genre: | ||
| # most_popular_genre[movie_genre["genre"]] += 1 | ||
|
|
||
| # else: | ||
| # most_popular_genre[movie_genre["genre"]] = 1 | ||
|
|
||
| # max_value_genre=max(most_popular_genre, key= most_popular_genre.get) | ||
| # return max_value_genre | ||
|
|
||
| # # https://www.programiz.com/python-programming/methods/built-in/max |
There was a problem hiding this comment.
if this isn't the way you want to implement it then you can remove this commented code
| friend_movie_set = set() | ||
| for movie in user_watched: | ||
| user_movie_set.add(movie["title"]) | ||
| print(user_movie_set) |
|
|
||
| #Wave_Three Part 1 | ||
|
|
||
| def get_unique_watched(user_data): |
| friend_movie_set = set() | ||
| for movie in user_watched: | ||
| user_movie_set.add(movie["title"]) | ||
| print(user_movie_set) |
|
|
||
| def get_available_recs(user_data): | ||
| users_subscription = user_data["subscriptions"] | ||
| friends_unique_movies = get_friends_unique_watched(user_data) |
| for movies_watched in friends_movie_list: | ||
| if movies_watched["host"] in users_subscription and movies_watched not in movie_subscription: | ||
| movie_subscription.append(movies_watched) | ||
| print(movie_subscription) |
|
|
||
|
|
||
|
|
||
| def get_available_recs(user_data): |
There was a problem hiding this comment.
This is a good implementation. I want to offer a suggestion that uses fewer lines of code.
def get_available_recs(user_data): recommended_movies = [] friends_unique_watched = get_friends_unique_watched(user_data) for movie in friends_unique_watched: if movie["host"] in user_data["subscriptions"]: recommended_movies.append(movie) return recommended_movies
| def get_available_recs(user_data): | ||
| users_subscription = user_data["subscriptions"] | ||
| friends_unique_movies = get_friends_unique_watched(user_data) | ||
| users_friends = user_data["friends"] | ||
| users_friends_watched_movie = user_data["friends"] | ||
|
|
||
|
|
||
| friends_movie_list = [] | ||
| for watched_movies in users_friends: | ||
|
|
||
|
|
||
| for movies in watched_movies["watched"]: | ||
| friends_movie_list.append(movies) | ||
|
|
||
| movie_subscription = [] | ||
| for movies_watched in friends_movie_list: | ||
| if movies_watched["host"] in users_subscription and movies_watched not in movie_subscription: | ||
| movie_subscription.append(movies_watched) | ||
| print(movie_subscription) | ||
|
|
||
|
|
||
| user_title =[] | ||
| for watched_movie in user_data["watched"]: | ||
| user_title.append(watched_movie["title"]) | ||
|
|
||
|
|
||
| recommendations =[] | ||
|
|
||
| if not user_data["watched"]: | ||
| return movie_subscription | ||
| for movie in movie_subscription: | ||
| if movie["title"] not in user_title: | ||
| recommendations.append(movie) | ||
| return recommendations |
There was a problem hiding this comment.
This is a good implementation but I wanted to offer a solution that uses less lines of code
| def get_available_recs(user_data): | |
| users_subscription = user_data["subscriptions"] | |
| friends_unique_movies = get_friends_unique_watched(user_data) | |
| users_friends = user_data["friends"] | |
| users_friends_watched_movie = user_data["friends"] | |
| friends_movie_list = [] | |
| for watched_movies in users_friends: | |
| for movies in watched_movies["watched"]: | |
| friends_movie_list.append(movies) | |
| movie_subscription = [] | |
| for movies_watched in friends_movie_list: | |
| if movies_watched["host"] in users_subscription and movies_watched not in movie_subscription: | |
| movie_subscription.append(movies_watched) | |
| print(movie_subscription) | |
| user_title =[] | |
| for watched_movie in user_data["watched"]: | |
| user_title.append(watched_movie["title"]) | |
| recommendations =[] | |
| if not user_data["watched"]: | |
| return movie_subscription | |
| for movie in movie_subscription: | |
| if movie["title"] not in user_title: | |
| recommendations.append(movie) | |
| return recommendations | |
| def get_available_recs(user_data): | |
| recommended_movies = [] | |
| friends_unique_watched = get_friends_unique_watched(user_data) | |
| for movie in friends_unique_watched: | |
| if movie["host"] in user_data["subscriptions"]: | |
| recommended_movies.append(movie) | |
| return recommended_movies |
| #Wave 5 Part 1 | ||
|
|
||
|
|
||
| def get_new_rec_by_genre(user_data): |
There was a problem hiding this comment.
Good implementation and use of helper functions. How could you also use get_friends_unique_watched(user_data)?
| # for friends in users_friends: # {'watched': [{'title': 'Title A', 'host': 'Service A'}, {'title': 'Title C', 'host': 'Service C'}]} | ||
| # for friends in (friends["watched"]): #{'title': 'Title A', 'host': 'Service A'} --> friends_movies | ||
| # if movie["host"] and movie["title"]: | ||
| # friends_movie_list.append(movie["watched"]) | ||
| # # print(m) | ||
| # # print(friends_movie_list) | ||
| # return friends_movie_list | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| # users_movie = user_data["watched"] | ||
| # users_friends = user_data["friends"] | ||
| # users_subscription = user_data["subscriptions"] | ||
| # recommended_movie_list = [] | ||
| # friends_movies_list = [] | ||
| # friends_movies_list1 = [] | ||
| # final_recommendations = [] |
There was a problem hiding this comment.
remove code once you are done testing/debugging
|
|
||
|
|
||
| #wave 5 Part 2 | ||
| def get_rec_from_favorites(user_data): |
There was a problem hiding this comment.
what helper functions could you also use here?
|
Great job! I like how you thought through alternative ways to approach the functions. I added comments on refactoring your code, removing unused code, and the use of the helper functions. |
No description provided.