Калоян обнови решението на 31.03.2013 14:25 (преди над 11 години)
+class Person:
+ def _update_children(self, new_child):
+ if new_child.gender == 'M':
+ [child.brothers.append(new_child)
+ for child
+ in self._children
+ if new_child != child]
+ else:
+ [child.sisters.append(new_child)
+ for child
+ in self._children
+ if new_child != child]
+
+ def __init__(self, name, gender, birth_year=0, father=None, mother=None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.father = father
+ self.mother = mother
+
+ self.brothers = []
+ self.sisters = []
+ self._children = []
+
+ if father is not None and mother is not None:
+ if(birth_year - father.birth_year < 18 or
+ birth_year - mother.birth_year < 18):
+ self.father = None
+ self.mother = None
+ else:
+ father._children.append(self)
+ mother._children.append(self)
+ father._update_children(self)
+
+ def get_brothers(self):
+ return self.brothers
+
+ def get_sisters(self):
+ return self.sisters
+
+ def children(self, gender='*'):
+ if gender != '*':
+ return [x for x in self._children if x.gender == gender]
+ else:
+ return self._children
+
+ def is_direct_successor(self, predecessor):
+ #return predecessor == self.mother or predecessor == self.father
+ return predecessor in self._children