Христина обнови решението на 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