mardi 20 mars 2018

Trying to append List/array based on condition [duplicate]

This question already has an answer here:

I'm trying to add to an array based on a condition. Can someone clarify why the if statement isn't working as I intend it to?

all_staff = ["Judith", "Harry", "Jonathan", "Reuben"]
new_staff = []


def person_finder(staff):
for x in staff:
    if x == "Reuben" or "Harry" or "Jonathan":
        new_staff.append(x)
    else:
        continue
    return new_staff


selected = person_finder(all_staff)


def the_men(people):
for x in people:
    print(x + " is a man")


the_men(selected)

This returns:

Judith is a man

Aucun commentaire:

Enregistrer un commentaire