Свилен обнови решението на 29.03.2013 23:25 (преди над 11 години)
+class Person:
+
+ def __init__(self, name, gender, birth_year, **kwargs):
+ self.name = name
+ self.gender = gender
+ self.birth_year = birth_year
+ self.current_children = set()
+
+ mother = kwargs.get('mother', None)
+ father = kwargs.get('father', None)
+
+ if father is not None:
+ father.current_children.add(self)
+ if mother is not None:
+ mother.current_children.add(self)
+
+ self.father = father
+ self.mother = mother
+
+ def get_all_clidren(self, gender):
+ all_children = []
+ if self.mother is not None:
+ all_children += (list(filter(lambda x: x.gender == gender
+ and x is not self,
+ self.mother.current_children)))
+ if self.father is not None:
+ all_children += (list(filter(lambda x: x.gender == gender
+ and x is not self
+ and not x in all_children,
+ self.father.current_children)))
+ return all_children
+
+ def is_direct_successor(self, other):
+ return other in self.current_children
+
+ def get_brothers(self):
+ return self.get_all_clidren('M')
+
+ def get_sisters(self):
+ return self.get_all_clidren('F')
+
+ def children(self, gender=None):
+ if gender is not None:
+ return list(filter(lambda x: x.gender == gender,
+ self.current_children))
+ else:
+ return self.current_children