Кристиян обнови решението на 29.03.2013 20:21 (преди над 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
+ if father != None:
+ father.inheritors.append(self)
+ self.mother = mother
+ if mother != None:
+ mother.inheritors.append(self)
+ self.inheritors = []
+
+ def get_brothers(self):
+ return list(set([x for x in self.father.inheritors
+ if x.gender == 'M' and x != self] +
+ [x for x in self.mother.inheritors
+ if x.gender == 'M' and x != self]))
+
+ def get_sisters(self):
+ return list(set([x for x in self.father.inheritors
+ if x.gender == 'F' and x != self] +
+ [x for x in self.mother.inheritors
+ if x.gender == 'F' and x != self]))
+
+ def children(self, gender=''):
+ if gender == 'F' or gender == 'M':
+ return [x for x in self.inheritors if gender == x.gender]
+ else:
+ return [x for x in self.inheritors]
+
+ def is_direct_successor(self, relative):
+ if (relative in self.children()):
+ return True
+ else:
+ return False