Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Person #1641

Open
wants to merge 26 commits into
base: python-add-person-class
Choose a base branch
from

Conversation

ProgrammerYaroslav
Copy link

@@ -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
‎checklist.md
+15
-3

Original file line number Diff line number Diff line change
@@ -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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants