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

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

Към профила на Радослав Рачев

Резултати

  • 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._children = list()
for parent in self._get_known_parents():
parent._add_child(self)
def _add_child(self, child):
self._children.append(child)
def _get_known_parents(self):
return [parent for parent in [self.mother, self.father] if
parent is not None]
def _get_siblings(self, gender):
siblings = set()
for parent in self._get_known_parents():
siblings |= set(parent.children(gender))
siblings -= {self}
return siblings
def get_brothers(self):
return list(self._get_siblings('M'))
def get_sisters(self):
return list(self._get_siblings('F'))
def children(self, gender=None):
if gender:
return [child for child in self._children if
child.gender == gender]
else:
return self._children
def is_direct_successor(self, person):
return person.mother is self or person.father is self

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

...........
----------------------------------------------------------------------
Ran 11 tests in 0.006s

OK

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

Радослав обнови решението на 31.03.2013 20:20 (преди над 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._children = list()
+
+ for parent in [mother, father]:
+ if parent:
+ parent._add_child(self)
+
+ def _add_child(self, child):
+ self._children.append(child)
+
+ def __get_known_parents(self):
+ return [parent for parent in [self.mother, self.father] if
+ parent is not None]
+
+ def __get_siblings(self, gender):
+ siblings = set()
+ for parent in self.__get_known_parents():
+ siblings |= set(parent.children(gender))
+ siblings -= {self}
+ return siblings
+
+ def get_brothers(self):
+ return list(self.__get_siblings('M'))
+
+ def get_sisters(self):
+ return list(self.__get_siblings('F'))
+
+ def children(self, gender=None):
+ if gender:
+ return [child for child in self._children if
+ child.gender == gender]
+ else:
+ return self._children
+
+ def is_direct_successor(self, person):
+ return person.mother == self or person.father == self

Радослав обнови решението на 31.03.2013 20:23 (преди над 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._children = list()
- for parent in [mother, father]:
- if parent:
- parent._add_child(self)
+ for parent in self.__get_known_parents():
+ parent._add_child(self)
def _add_child(self, child):
self._children.append(child)
def __get_known_parents(self):
return [parent for parent in [self.mother, self.father] if
parent is not None]
def __get_siblings(self, gender):
siblings = set()
for parent in self.__get_known_parents():
siblings |= set(parent.children(gender))
siblings -= {self}
return siblings
def get_brothers(self):
return list(self.__get_siblings('M'))
def get_sisters(self):
return list(self.__get_siblings('F'))
def children(self, gender=None):
if gender:
return [child for child in self._children if
child.gender == gender]
else:
return self._children
def is_direct_successor(self, person):
return person.mother == self or person.father == self

Радослав обнови решението на 31.03.2013 20:31 (преди над 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._children = list()
for parent in self.__get_known_parents():
parent._add_child(self)
def _add_child(self, child):
self._children.append(child)
def __get_known_parents(self):
return [parent for parent in [self.mother, self.father] if
parent is not None]
def __get_siblings(self, gender):
siblings = set()
for parent in self.__get_known_parents():
siblings |= set(parent.children(gender))
siblings -= {self}
return siblings
def get_brothers(self):
return list(self.__get_siblings('M'))
def get_sisters(self):
return list(self.__get_siblings('F'))
def children(self, gender=None):
if gender:
return [child for child in self._children if
child.gender == gender]
else:
return self._children
def is_direct_successor(self, person):
- return person.mother == self or person.father == self
+ return person.mother is self or person.father is self

Радослав обнови решението на 01.04.2013 15:25 (преди над 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._children = list()
- for parent in self.__get_known_parents():
+ for parent in self._get_known_parents():
parent._add_child(self)
def _add_child(self, child):
self._children.append(child)
- def __get_known_parents(self):
+ def _get_known_parents(self):
return [parent for parent in [self.mother, self.father] if
parent is not None]
- def __get_siblings(self, gender):
+ def _get_siblings(self, gender):
siblings = set()
- for parent in self.__get_known_parents():
+ for parent in self._get_known_parents():
siblings |= set(parent.children(gender))
siblings -= {self}
return siblings
def get_brothers(self):
- return list(self.__get_siblings('M'))
+ return list(self._get_siblings('M'))
def get_sisters(self):
- return list(self.__get_siblings('F'))
+ return list(self._get_siblings('F'))
def children(self, gender=None):
if gender:
return [child for child in self._children if
child.gender == gender]
else:
return self._children
def is_direct_successor(self, person):
return person.mother is self or person.father is self