Станислав обнови решението на 30.03.2013 19:06 (преди над 11 години)
+class Person():
+ def __init__(self, **kwargs):
+ for arg in ('gender', 'name', 'birth_year'):
+ if arg in kwargs:
+ self.__setattr__(arg, kwargs[arg])
+ self.__children = set()
+ self.__parents = {parent: kwargs[parent]
+ for parent in ('father', 'mother')
+ if parent in kwargs}
+ for parent in self.__parents.values():
+ parent.add_child(self)
+
+ def children(self, gender=None):
+ return [child for child in self.__children
+ if gender in (child.gender, None)]
+
+ def get_siblings(self, gender=None):
+ return list({child for parent in self.__parents.values()
+ for child in parent.children()
+ if child is not self and gender in (child.gender, None)})
+
+ def get_sisters(self):
+ return self.get_siblings(gender='F')
+
+ def get_brothers(self):
+ return self.get_siblings(gender='M')
+
+ def add_child(self, child):
+ self.__children.add(child)
+
+ def is_direct_successor(self, person):
+ return person in self.children()