Петър обнови решението на 01.04.2013 11:54 (преди над 11 години)
+class Person:
+ def __init__(self, name, gender, birth_year, father=None, mother=None):
+ self.name = name
+ self.gender = gender
+ self.birth_year = birth_year
+ self.father = father
+ self.mother = mother
+ self.kids = []
+ if father is not None:
+ father.add_child(self)
+ if mother is not None:
+ mother.add_child(self)
+
+ def children(self, gender=None):
+ if gender is None:
+ return self.kids
+ else:
+ return list(filter(lambda x: x.gender is gender, self.kids))
+
+ def add_child(self, person):
+ self.kids.append(person)
+
+ def get_sisters(self):
+ sisters = []
+ if self.father is not None:
+ for x in self.father.kids:
+ if x.gender == "F" and x is not self:
+ sisters.append(x)
+ if self.mother is not None:
+ for x in self.mother.kids:
+ if x.gender == "F" and x not in sisters and x is not self:
+ sisters.append(x)
+ return sisters
+
+ def get_brothers(self):
+ brothers = []
+ if self.father is not None:
+ for x in self.father.kids:
+ if x.gender == "M" and x is not self:
+ brothers.append(x)
+ if self.mother is not None:
+ for x in self.mother.kids:
+ if x.gender == "M" and x not in brothers and x is not self:
+ brothers.append(x)
+ return brothers
+
+ def is_direct_successor(self, person):
+ return person in self.kids