Александър обнови решението на 28.03.2013 00:43 (преди над 11 години)
+class Person:
+
+ def __init__(self, name, gender, birth_year, father=None, mother=None):
+ self.name = name
+ self.gender = gender
+ self.birth_year = birth_year
+ self.father = father
+ self.mother = mother
+ self.children_list = []
+
+ if father:
+ father.children_list.append(self)
+ if mother:
+ mother.children_list.append(self)
+
+ def get_siblings(self, gender):
+ siblings_list = []
+
+ if self.mother:
+ siblings_list += list(filter(lambda x: x.gender == gender,
+ self.mother.children_list))
+ if self.father:
+ siblings_list += list(filter(lambda x: x.gender == gender,
+ self.father.children_list))
+
+ siblings_list = list(set(siblings_list))
+
+ if self in siblings_list:
+ siblings_list.remove(self)
+
+ return siblings_list
+
+ def get_brothers(self):
+ return self.get_siblings('M')
+
+ def get_sisters(self):
+ return self.get_siblings('F')
+
+ def children(self, gender=None):
+ if gender:
+ return list(filter(lambda x: x.gender == gender,
+ self.children_list))
+ else:
+ return self.children_list
+
+ def is_direct_successor(self, other):
+ return self in other.children_list or other in self.children_list