Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person:
- def __init__(self, name, gender, otherVar, otherVar2):
- self.name = name
- self.gender = gender
- self.otherVar = otherVar
- self.otherVar2 = otherVar2
- ## also more variables if that makes a difference
- John = Person("John", boy, otherVar, otherVar2)
- Jane = Person("Jane", girl, otherVar, otherVar2) ## etcetera
- myList = [John, Jane, Mary, Derek, Bob, Sue]
- simpleThingThatIdoNotUnderstand(): ## removes all the
- ## girls
- myList = [John, Derek, Bob]
- # removes all people of the specified gender
- def removePeopleByGender(people, gender):
- output = []
- for person in people:
- # assumes person.gender and gender are the same data type
- if (person.gender != gender):
- output.append(person)
- return output
- boys = [person for person in myList if person.gender == boy]
- myList = [John, Jane, Mary, Derek, Bob, Sue]
- new_list = [<expression> for <variable> in <original_list> if <condition>]
- new_list = []
- for <variable> in <original_list>:
- if <condition>:
- new_list.append(<expression>)
Add Comment
Please, Sign In to add comment