Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. from Person import Person
  2.  
  3.  
  4. def condition(person: Person):
  5. return person.age == 26
  6.  
  7.  
  8. def complexCondition(person: Person):
  9. return len(set(["Michał"]).intersection(person.friends)) > 0
  10.  
  11.  
  12. persons = []
  13. persons.append(Person("Maciek", 25, ["Michał", "Dominik"]))
  14. persons.append(Person("Paulinka", 26, ["Michał", "Jadzia"]))
  15. persons.append(Person("Robert", 26, ["Patka", "Jadzia"]))
  16.  
  17. print("First element that meets condition:")
  18. print(type(filter(condition, persons)))
  19. # maciek = next(condition, persons)
  20. # print(maciek.__dict__)
  21.  
  22.  
  23. print("All elements that meet condition:")
  24. for person in filter(condition, persons):
  25. print(person)
  26.  
  27.  
  28. print("All elements that meet condition, using lambda:")
  29. for person in filter(lambda p: p.age == 26, persons):
  30. print(person)
  31.  
  32.  
  33. print("All elements that meet complex condition")
  34. for person in filter(complexCondition, persons):
  35. print(person)
  36.  
  37.  
  38. print("All elements that meet complex condition")
  39. for person in filter(lambda p: len(set(["Michał"]).intersection(p.friends)) > 0, persons):
  40. print(person)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement