Мартин обнови решението на 29.03.2013 10:05 (преди над 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.__allchildren = []
+ if self.mother:
+ self.mother.__allchildren.append(self)
+ if self.father:
+ self.father.__allchildren.append(self)
+
+ def children(self, gender=''):
+ if gender:
+ return [child for child in self.__allchildren if child.gender == gender]
+ else:
+ return self.__allchildren
+
+ def __get_brothers_or_sisters(self, gender):
+ brothers_or_sisters = set()
+ if self.mother:
+ for child in self.mother.children(gender):
+ if child is not self:
+ brothers_or_sisters.add(child)
+ if self.father:
+ for child in self.father.children(gender):
+ if child is not self:
+ brothers_or_sisters.add(child)
+ return list(brothers_or_sisters)
+
+ def get_brothers(self):
+ return self.__get_brothers_or_sisters('M')
+
+ def get_sisters(self):
+ return self.__get_brothers_or_sisters('F')
+
+ def is_direct_successor(self, successor):
+ return True if successor in self.__allchildren else False