Giter Site home page Giter Site logo

py-person-class's Introduction

Class Person

You have a list of dicts people, every dict means a person, it has keys: name, age, wife/husband - depends on person is male or female. All names are different. Key wife/husband can be either None or name of another person.

Create class Person. It's __init__ method 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. The __init__ method should add elements to this attribute.

Write function create_person_list, this function takes list people and return list with Person instances instead of dicts.

Note:

If person's key wife/husband is not None - create_person_list should add attribute wife/husband respectively to its instance. This attribute should be a link to a Person instance with name the same as wife/husband key in person's dict.

Example:

people = [
    {"name": "Ross", "age": 30, "wife": "Rachel"},
    {"name": "Joey", "age": 29, "wife": None},
    {"name": "Rachel", "age": 28, "husband": "Ross"}
]

person_list = create_person_list(people) 
isinstance(person_list[0], Person) # True
person_list[0].name == "Ross"
person_list[0].wife is person_list[2] # True
person_list[0].wife.name == "Rachel"

person_list[1].name == "Joey"
person_list[1].wife
# AttributeError

isinstance(person_list[2], Person) # True
person_list[2].name == "Rachel"
person_list[2].husband is person_list[0] # True
# The same as person_list[0]
person_list[2].husband.name == "Ross"
person_list[2].husband.wife is person_list[2]  # True

Person.people == {
    "Ross": <__main__.Person object at 0x10c20ca60>,
    "Joey": <__main__.Person object at 0x10c180a00>,
    "Rachel": <__main__.Person object at 0x10c1804f0>
}

Hint - use pytest for testing

Note: Check your code using this checklist before pushing your solution.

py-person-class's People

Contributors

abnormaltype avatar dmytrosvirsa avatar masterpieceelbow avatar nattalli avatar y-havryliv avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.