Христо обнови решението на 29.03.2013 00:16 (преди над 11 години)
+class Person:
+
+ def __init__(self, name='', gender='', birth_year=None,
+ father=None, mother=None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.siblings = []
+ self._children = []
+ self.add_parrent(father)
+ self.add_parrent(mother)
+
+ def get_brothers(self):
+ return [brother for brother in self.siblings if brother.gender == 'M']
+
+ def get_sisters(self):
+ return [sister for sister in self.siblings if sister.gender == 'F']
+
+ def add_parrent(self, parrent):
+ if parrent is not None:
+ if parrent.gender == 'M':
+ self.father = parrent
+ self.add_siblings(parrent._children)
+ else:
+ self.mother = parrent
+ self.add_siblings(parrent._children)
+ if self not in parrent._children:
+ parrent._children.append(self)
+
+ def add_siblings(self, siblings):
+ for kid in siblings:
+ if kid not in self.siblings:
+ self.siblings.append(kid)
+ if self not in kid.siblings:
+ kid.siblings.append(self)
+
+ def children(self, gender='MF'):
+ return [kid for kid in self._children if kid.gender in gender]
+
+ def is_direct_successor(self, ancestor):
+ if ancestor in self._children:
+ return True
+ return False