Guest User

Untitled

a guest
Oct 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. class Person:
  2. def __init__(self, name, gender, otherVar, otherVar2):
  3. self.name = name
  4. self.gender = gender
  5. self.otherVar = otherVar
  6. self.otherVar2 = otherVar2
  7. ## also more variables if that makes a difference
  8.  
  9. John = Person("John", boy, otherVar, otherVar2)
  10. Jane = Person("Jane", girl, otherVar, otherVar2) ## etcetera
  11.  
  12.  
  13. myList = [John, Jane, Mary, Derek, Bob, Sue]
  14. simpleThingThatIdoNotUnderstand(): ## removes all the
  15. ## girls
  16. myList = [John, Derek, Bob]
  17.  
  18. # removes all people of the specified gender
  19. def removePeopleByGender(people, gender):
  20. output = []
  21.  
  22. for person in people:
  23. # assumes person.gender and gender are the same data type
  24. if (person.gender != gender):
  25. output.append(person)
  26.  
  27. return output
  28.  
  29. boys = [person for person in myList if person.gender == boy]
  30.  
  31. myList = [John, Jane, Mary, Derek, Bob, Sue]
  32.  
  33. new_list = [<expression> for <variable> in <original_list> if <condition>]
  34.  
  35. new_list = []
  36. for <variable> in <original_list>:
  37. if <condition>:
  38. new_list.append(<expression>)
Add Comment
Please, Sign In to add comment