Conversation
| @@ -0,0 +1,182 @@ | |||
|
|
|||
| def create_movie(title, genre, rating): | |||
| else: | ||
| return None | ||
|
|
||
| def add_to_watched(user_data, movie): |
| user_data["watched"].append(movie) | ||
| return user_data | ||
|
|
||
| def add_to_watchlist(user_data, movie): |
| #if title and genre and rating: | ||
| # movie_dict = {"title": title, | ||
| # "genre" :genre, | ||
| # "rating": rating, | ||
| # } | ||
| # return movie_dict | ||
| # else: | ||
| # return None | ||
|
|
||
|
|
||
| # def add_to_watched(user_data, movie): | ||
| # watched = user_data["watched"] | ||
| # if movie: | ||
| # watched.append(movie) | ||
| # else: | ||
| # watched = [] | ||
| # return user_data |
There was a problem hiding this comment.
When you are finished with a project/branch you would remove unused code when making a pull request
| if title in movie["title"]: | ||
| watch_list.remove(movie) | ||
| watched.append(movie) | ||
| return user_data#def create_movie(title,genre,rating): |
There was a problem hiding this comment.
| return user_data#def create_movie(title,genre,rating): | |
| return user_data |
|
|
||
| for movie in watch_list: | ||
| if title in movie["title"]: | ||
| watch_list.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/
| # avg_rating = 0.0 | ||
| # rating_sum = 0 | ||
| # for i in range (len(user_data["watched"])): | ||
| # rating_sum += user_data["watched"][i]["rating"] | ||
| # #calculating | ||
| # rating_sum/len(user_data["watched"]) |
| total_rating = 0 | ||
| if len(user_data["watched"]) == 0: | ||
| return 0 | ||
| else: | ||
| for movie in user_data["watched"]: | ||
| total_rating += movie["rating"] | ||
| return total_rating/len(user_data["watched"]) |
|
|
||
|
|
||
|
|
||
| def get_most_watched_genre(user_data): |
There was a problem hiding this comment.
great use of a frequency map here and the use of the max method
|
|
||
| # Wave 3 | ||
|
|
||
| def get_unique_watched(user_data): |
|
|
||
| for watched_list in user_data["friends"]: | ||
| for movie in watched_list["watched"]: | ||
| if movie not in user_data["watched"] and movie not in movies_friends_watched: |
|
|
||
| #Wave 4 | ||
|
|
||
| def get_available_recs(user_data): |
There was a problem hiding this comment.
this is a good implementation. Think about how you could of use one of your previously created functions get_friends_unique_watched(user_data) here to save some lines of code.
| if movie["host"] in host: | ||
| if movie not in rec_list: |
There was a problem hiding this comment.
you could also use a compound statement here as you did in the previous function like if movie["host"] not in user_title and movie not in rec_list:
| user_most_watched_genre = get_most_watched_genre(user_data) | ||
| friends_unique_list = get_friends_unique_watched(user_data) |
|
|
||
|
|
||
| def get_rec_from_favorites(user_data): | ||
| user_unique_list = get_unique_watched(user_data) |
| # def get_new_rec_by_genre(user_data): | ||
| # recommended_genre = [] | ||
| # new_list = [] | ||
| # fave_genre = get_most_watched_genre(user_data) | ||
| # for movie in user_data["friends"]: | ||
| # for i in movie["watched"]: | ||
| # new_list.append(i) | ||
| # for movie in new_list: | ||
| # if movie["genre"] == fave_genre: | ||
| # recommended_genre.append(movie) | ||
| # return recommended_genre | ||
| # def get_rec_from_favorites(user_data): | ||
| # recs_from_faves = [] | ||
| # unique_watched_list = get_unique_watched(user_data) | ||
| # faves = user_data["favorites"] | ||
| # for movie in unique_watched_list: | ||
| # if movie in faves: | ||
| # recs_from_faves.append(movie) | ||
| # return recs_from_faves | ||
|
|
||
| # def get_new_rec_by_genre: No newline at end of file |
There was a problem hiding this comment.
remove other attempts from code to clean it up
|
Great job! I added some comments on refactoring your code, removing unused code, and the use of helper functions. |
No description provided.