users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 10, "review": "Masterpiece"}
}
}
In utils/actions.py
Write a function,add_movie(user: str, movie: str, rating: int, review: str, users: dict),
that adds a movie to users watchlist with a rating and a review.
If the user does not exist, create them. Example:
>>> users = {}
>>> add_movie("Alice", "Inception", 9, "Mind-bending!", users)
>>> print(users)
{'Alice': {'Inception': {'rating': 9, 'review': 'Mind-bending!'}}}
users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 10, "review": "Masterpiece"}
}
}
In utils/actions.py
Write a function, update_review(user:str, movie: str, review: str, users: dict),
that updates a user's review for a given movie.
If the movie or user doesn't exist, do nothing. Example:
>>> update_review("Alice", "Inception", "Amazing concept!", users)
>>> print(users["Alice"]["Inception"])
{'rating': 9, 'review': 'Amazing concept!'}
users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 10, "review": "Masterpiece"}
}
}
In utils/insights.py
Write a function, get_user_average_rating(user: str, users: dict),
that returns the average rating a user has given.
If the user has no ratings, return None. Example:
>>> get_user_average_rating("Alice", users)
8.0
users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 10, "review": "Masterpiece"}
}
}
In utils/insights.py
Write a function, {get_most_rated_movies(users: dict)}, that returns a list of movies
sorted by how many users have rated them (most to least). Example:
>>> get_most_rated_movies(users)
[('Inception', 2), ('Titanic', 1), ('Interstellar', 1)]
users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 10, "review": "Masterpiece"}
}
}
In utils/insights.py
Write a function, get_top_rated_movies(users: dict, min_ratings: int),
that returns a list of movies sorted from the highest average ratings to lowest average ratings,
but only include those with at least min_ratings users. Example:
>>> get_top_rated_movies(users, min_ratings=2)
[(8.5, 'Inception')]
>>> get_top_rated_movies(users, min_ratings=1)
[(10.0, 'Interstellar'), (8.5, 'Inception'), (7.0, 'Titanic')]
"users": {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"},
"Avatar": {"rating": 8, "review": "Immersive"}
},
"Charlie": {
"Inception": {"rating": 10, "review": "Amazing"},
"Titanic": {"rating": 6, "review": "Emotional"},
"Avatar": {"rating": 7, "review": "Nice"}
}
}
In utils/insights.py
Write a function, get_similarity(user1: str, user2: str, users: dict),
that returns a similarity score between two users based on ratings of common movies.
Use the sum of absolute differences in rating (lower score = more similar).
If no common movies, return None. Example:
>>> get_similarity("Alice", "Charlie", users)
3 # |9-10| + |7-6| + |8-7| = 1+1+1 = 3
users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"},
"The Matrix": {"rating": 10, "review": "Revolutionary sci-fi"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 10, "review": "Masterpiece"},
"The Dark Knight": {"rating": 9, "review": "Best superhero movie"}
},
"Charlie": {
"Titanic": {"rating": 9, "review": "Very emotional"},
"Avatar": {"rating": 8, "review": "Visually stunning"},
"Gladiator": {"rating": 9, "review": "Epic historical drama"}
}
}
In utils/insights.py
Write a function, suggest_movie(user: str, users: dict) that suggests a movie
to a user based on what similar users have rated highly,
which the current user hasn't rated. Use the user with the lowest similarity score. Example:
>>> suggest_movie("Alice", users)
"Interstellar"
>>> suggest_movie("Bob", users)
"The Matrix"
users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 8, "review": "Masterpiece"},
"The Shawshank Redemption": {"rating": 10, "review": "Masterpiece"}
}
}
In utils/insights.py
Write a function, get_most_active_user(users: dict), that returns the name of the user
who has rated the most movies. Example:
>>> get_most_active_user(users)
'Bob'
users = {
"Alice": {
"Inception": {"rating": 9, "review": "Mind-bending!"},
"Titanic": {"rating": 7, "review": "Too long, but emotional"}
},
"Bob": {
"Inception": {"rating": 8, "review": "Loved the visuals"},
"Interstellar": {"rating": 10, "review": "Masterpiece"}
}
}
In main.py
Write a function, {generate_summary_report(users: dict)}, that prints a full report of the movie system, including:
- Most active user
- Average rating per user
- Most rated movies
- Top-rated movies (with minimum 2 ratings)
- Suggested movies for each user
>>> generate_summary_report(users)
Movie Watchlist & Review System Summary
==================================================
Most active user: Bob
Average Rating Per User:
- Alice: 8.00
- Bob: 9.00
Most Rated Movies:
- Inception: 2 ratings
- Interstellar: 1 rating
Top Rated Movies (min 2 ratings):
- Inception: 8.50 average rating
Recommendations:
- Alice: Interstellar
- Bob: No suggestions at the moment.