From d21cafc3902250e24676e87f03d5c0800aea570b Mon Sep 17 00:00:00 2001 From: Viktoriia Rybenchuk Date: Fri, 25 Oct 2024 12:09:30 +0300 Subject: [PATCH] update README.md and checklist.md --- README.md | 18 ++++++++++++------ checklist.md | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 398cb986a..504614761 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,19 @@ a **person**, it has keys: `name`, `age`, female. All `names` are different. Key `wife`/`husband` can be either `None` or name of another person. +1. **Define a Class `Person`** + +2. **The `__init__` method should take two parameters** + - `name`: A string representing the name of the person. + - `age`: An integer representing the age of the person. -Create class `Person`. It's constructor takes -and store `name`, `age` of a person. -This class also should have a class attribute -`people`, it is a dict that stores `Person` -instances by their `name`. Constructor should -add elements to this attribute. + +3. **Define a **class attribute** `people` in the `Person` class to store instances by their `name`.** + - The keys are the `name` values of instances. + - The values are references to the `Person` instances themselves. + - Within the `__init__` method, add each new `Person` instance to the `people` dictionary. + + Write function `create_person_list`, this function takes list `people` and return list with diff --git a/checklist.md b/checklist.md index f34177a78..45d8d7eb1 100644 --- a/checklist.md +++ b/checklist.md @@ -18,8 +18,20 @@ def get_full_name(x: str, y: str) -> str: ``` 2. Avoid nested `if` by using `and`, `or` logical operators. +3. When creating a list of instances from a collection (such as a list of dictionaries), it is recommended to use **list comprehension** rather than traditional `for` loops. +4. When accessing values in a dictionary, it is better to use the `dict.get()` method instead of explicitly checking for the presence of a key. This approach simplifies the code and avoids potential `KeyError` exceptions, making it cleaner and more concise. -## Clean Code + Cood example: + +```python +if person.get('wife'): + pass +``` -Add comments, prints, and functions to check your solution when you write your code. -Don't forget to delete them when you are ready to commit and push your code. + Bad example: +```python +if "wife" in person and person["wife"]: + pass +``` +## Clean Code +There is no need to add comments to the code as it is clear and self-explanatory.