Applying Data Filtering and Aggregation in User Data Management
Introduction
Welcome to today's lesson on applying data filtering and aggregation in a real-world scenario using a user management system. We'll start by building a foundational structure that can handle basic user operations. Then, we'll expand it by introducing more advanced functionalities that allow filtering and aggregating user data.
Starter Task Methods
In our starter task, we will implement a class that manages basic operations on a collection of user data, specifically handling adding new users, retrieving user profiles, and updating user profiles.
Here are the starter task methods:
add_user(self, user_id: str, age: int, country: str, subscribed: bool) -> bool- adds a new user with the specified attributes. ReturnsTrueif the user was added successfully andFalseif a user with the sameuser_idalready exists.get_user(self, user_id: str) -> dict[str, int | str | bool] | None- returns the user's profile as a dictionary if the user exists; otherwise, returnsNone.update_user(self, user_id: str, age: int | None, country: str | None, subscribed: bool | None) -> bool- updates the user's profile based on non-None parameters. ReturnsTrueif the user exists and was updated,Falseotherwise.
Solution for the Starter Task
Here is the implementation of our starter task:
This implementation covers all our starter methods. Let's move forward and introduce more complex functionalities.
