Марио обнови решението на 01.04.2013 15:43 (преди около 12 години)
+class Person:
+
+ def __init__(self, name, birth_year, gender, father=None, mother=None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.father = father
+ self.mother = mother
+ if mother is not None:
+ mother.children_set.add(self)
+ if father is not None:
+ father.children_set.add(self)
+ self.children_set = set()
+
+ def get_siblings(self, gender):
+ siblings = {child for child in self.mother.children_set
+ if child.gender == gender}
+ siblings = siblings.union({child for child in self.father.children_set
+ if child.gender == gender})
+ return list(siblings)
+
+ def get_brothers(self):
+ return self.get_siblings('M')
+
+ def get_sisters(self):
+ return self.get_siblings('F')
+
+ def children(self, gender=None):
+ if gender is None:
+ return list(self.children_set)
+ else:
+ return [child for child in self.children_set
+ if child.gender == gender]
+
+ def is_direct_successor(self, other_person):
+ return other_person.mother is self or other_person.father is self