Красимира обнови решението на 29.03.2013 11:15 (преди над 11 години)
+class Person:
+
+ def __init__(self, name, birth_year, gender,
+ father=None, mother=None):
+ self.name, self.birth_year, self.gender = name, birth_year, gender
+ self.mother, self.father = mother, father
+ if self.mother:
+ mother.add_children(self)
+ if self.father:
+ father.add_children(self)
+ self.children_list = []
+
+ def add_children(self, *args):
+ self.children_list.extend(args)
+
+ def children(self, gender=""):
+ return [child for child in self.children_list
+ if not gender or child.gender == gender]
+
+ def siblings(self, gender=""):
+ parents_children = []
+ if self.mother:
+ parents_children.extend(self.mother.children(gender))
+ if self.father:
+ parents_children.extend(self.father.children(gender))
+ return set([child for child in parents_children if child is not self])
+
+ def get_brothers(self):
+ return list(self.siblings("M"))
+
+ def get_sisters(self):
+ return list(self.siblings("F"))
+
+ def is_direct_successor(self, person):
+ return person in self.children() or self in person.children()