Решение на Родословно дърво от Христина Христова

Обратно към всички решения

Към профила на Христина Христова

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 11 успешни тест(а)
  • 0 неуспешни тест(а)

Код

class Person:
def __init__(self, name, birth_year, gender, mother=None, father=None):
self.name = name
self.birth_year = birth_year
self.gender = gender
self.mother = mother
self.father = father
self.list_of_children = []
if self.mother:
self.mother.list_of_children.append(self)
if self.father:
self.father.list_of_children.append(self)
def children(self, gender=None):
return [child for child in self.list_of_children
if not gender or child.gender == gender]
def get_siblings(self, gender):
all_parents_children = set(self.mother.children(gender)
+ self.father.children(gender))
return list(all_parents_children - {self})
def get_brothers(self):
return self.get_siblings('M')
def get_sisters(self):
return self.get_siblings('F')
def is_direct_successor(self, successor):
return successor.mother is self or successor.father is self

Лог от изпълнението

...........
----------------------------------------------------------------------
Ran 11 tests in 0.007s

OK

История (2 версии и 0 коментара)

Христина обнови решението на 30.03.2013 09:56 (преди над 11 години)

+class Person:
+
+ def __init__(self, name, birth_year, gender, mother=None, father=None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.mother = mother
+ self.father = father
+ self.list_of_children = []
+ if self.mother:
+ self.mother.list_of_children.append(self)
+ if self.father:
+ self.father.list_of_children.append(self)
+
+ def children(self, gender=None):
+ return [child for child in self.list_of_children
+ if not gender or child.gender == gender]
+
+ def get_brothers(self):
+ return list(set(self.mother.children('M') + self.father.children('M'))
+ - {self})
+
+ def get_sisters(self):
+ return list(set(self.mother.children('F') + self.father.children('F'))
+ - {self})
+
+ def is_direct_successor(self, successor):
+ return successor.mother is self or successor.father is self

Христина обнови решението на 31.03.2013 17:49 (преди над 11 години)

class Person:
def __init__(self, name, birth_year, gender, mother=None, father=None):
self.name = name
self.birth_year = birth_year
self.gender = gender
self.mother = mother
self.father = father
self.list_of_children = []
if self.mother:
self.mother.list_of_children.append(self)
if self.father:
self.father.list_of_children.append(self)
def children(self, gender=None):
return [child for child in self.list_of_children
if not gender or child.gender == gender]
+ def get_siblings(self, gender):
+ all_parents_children = set(self.mother.children(gender)
+ + self.father.children(gender))
+ return list(all_parents_children - {self})
+
def get_brothers(self):
- return list(set(self.mother.children('M') + self.father.children('M'))
- - {self})
+ return self.get_siblings('M')
def get_sisters(self):
- return list(set(self.mother.children('F') + self.father.children('F'))
- - {self})
+ return self.get_siblings('F')
def is_direct_successor(self, successor):
return successor.mother is self or successor.father is self