Марина обнови решението на 01.04.2013 01:52 (преди над 11 години)
+class Person:
+ def __init__(self, name, birth_year, gender, mother=None, father=None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.kids = []
+ self.mother = mother
+ self.father = father
+
+ if self.mother:
+ self.mother.kids.append(self)
+
+ if self.father:
+ self.father.kids.append(self)
+
+ def children(self, **kwargs):
+ if kwargs:
+ child = []
+ for x in self.kids:
+ if x.gender == kwargs['gender']:
+ child.append(x)
+ return child
+
+ else:
+ return self.kids
+
+ def get_brothers(self):
+ mothers_kids = []
+ fathers_kids = []
+
+ if self.mother:
+ mothers_kids = list({child for child in self.mother.children()
+ if (child.gender == 'M' or child.gender == 'm')
+ and child is not self})
+
+ if self.father:
+ fathers_kids = list({child for child in self.father.children()
+ if (child.gender == 'M' or child.gender == 'm')
+ and child is not self})
+
+ return mothers_kids + fathers_kids
+
+ def get_sisters(self):
+ mothers_kids = []
+ fathers_kids = []
+
+ if self.mother:
+ mothers_kids = list({child for child in self.mother.children()
+ if (child.gender == 'F' or child.gender == 'f')
+ and child is not self})
+
+ if self.father:
+ fathers_kids = list({child for child in self.children()
+ if (child.gender == 'F' or child.gender == 'f')
+ and child is not self})
+
+ return mothers_kids + fathers_kids
+
+ def is_direct_successor(self, successor):
+
+ if successor in self.kids:
+ return True
+
+ else:
+ return False