Ocelots - Larissa A.#18
Conversation
|
|
||
| def create_movie(title, genre, rating): | ||
| pass | ||
| def create_movie(title=None, genre=None, rating=None): |
There was a problem hiding this comment.
Really excellent use of comments to describe your functions!
| # ******************************************************************************************* | ||
|
|
||
| @pytest.mark.skip() | ||
| # Added assertions to test if correct movie was added to "watched" |
There was a problem hiding this comment.
Good addition of the test. And for completeness, we could test the other attributes as well ("genre", "rating")
| # create dictionary with movie details | ||
| new_movie = {} | ||
| keys = ["title", "genre", "rating"] | ||
| for key, det in zip(keys, dets): |
| for key, det in zip(keys, dets): | ||
| new_movie[key] = det | ||
| # handle missing movie details | ||
| if any(x == None for x in dets): |
There was a problem hiding this comment.
nice concise use of any() and this list checking syntax!
There was a problem hiding this comment.
Could this check have occurred earlier in the function, in order to be more efficient and skip unused code?
There was a problem hiding this comment.
Also, good check for None; other cases to validate could include a blank string, ""
| # copy user data | ||
| updated_data = janes_data.copy() | ||
| # iterate through watchlist movies | ||
| for movie in updated_data['watchlist']: |
There was a problem hiding this comment.
This code passes the tests, but as an aside it contains an "anti-pattern" that is important to be aware of. An element of the list that is being iterated over is being removed inside the for loop. This is generally considered bad practice and can leave you open to problems in more complex code. One solution could be to copy the data you get from "movie in updated_data['watchlist']" into a variable that's not going to change as you modify updated_data.
| ratings = [] | ||
| for movie in janes_data['watched']: | ||
| ratings.append(movie['rating']) | ||
| if len(ratings) == 0: |
| if len(genres) == 0: | ||
| return None | ||
| # collect highest frequency movie genre | ||
| popular_genre = statistics.mode(genres) |
There was a problem hiding this comment.
Good use of an established specialized library function
| # ----------------------------------------- | ||
|
|
||
|
|
||
| def get_unique_watched(amandas_data): |
There was a problem hiding this comment.
Good solution! Can you think of how sets might be used for an even simpler implementation? Though, I do think it's useful to have gone through the foundations and understanding what might be going on behind the scenes with sets.
| return amandas_unique_movies | ||
|
|
||
|
|
||
| def get_friends_unique_watched(amandas_data): |
No description provided.