Камелия обнови решението на 29.03.2013 12:08 (преди над 11 години)
+class Person:
+
+ def __init__(self, name, gender, birth_year,
+ mother=None, father=None):
+ self.name = name
+ self.gender = gender
+ self.birth_year = birth_year
+ self.mother = mother
+ self.father = father
+ self.children_list = []
+ if mother is not None:
+ mother.children_list.append(self)
+ if father is not None:
+ father.children_list.append(self)
+
+ def get_siblings(self, _gender):
+ result = {}
+ if self.mother is not None:
+ result = set(self.mother.children(gender=_gender))
+ if self.father is not None:
+ result = result.union(set(self.father.children(gender=_gender)))
+ if self in result:
+ result = result.remove(self)
+ return list(result)
+
+ def get_brothers(self):
+ return self.get_siblings('M')
+
+ def get_sisters(self):
+ return self.get_siblings('F')
+
+ def children(self, gender=None):
+ result = []
+ if gender is not None:
+ for child in self.children_list:
+ if child.gender == gender:
+ result.append(child)
+ else:
+ result = self.children_list
+ return result
+
+ def is_direct_successor(self, other):
+ return other in self.children()