Python Forum
Trying to append List/array based on condition
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to append List/array based on condition
#1
I'm having problems appending array based on an if statement.

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" .format(people))


the_men(selected)
This returns:

Judith is a man
Reply
#2
(Mar-20-2018, 12:18 PM)Mr_Keystrokes Wrote:
if x == "Reuben" or "Harry" or "Jonathan":

That isn't doing what you think it's doing. Head over this way, and read this :) https://python-forum.io/Thread-Multiple-...or-keyword
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  append str to list in dataclass flash77 6 345 Mar-14-2024, 06:26 PM
Last Post: flash77
  unable to remove all elements from list based on a condition sg_python 3 377 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Sent email based on if condition stewietopg 1 805 Mar-15-2023, 08:54 AM
Last Post: menator01
Question How to append integers from file to list? Milan 8 1,364 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  create new column based on condition arvin 12 2,134 Dec-13-2022, 04:53 PM
Last Post: jefsummers
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 799 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  functional LEDs in an array or list? // RPi user Doczu 5 1,522 Aug-23-2022, 05:37 PM
Last Post: Yoriz
  read a text file, find all integers, append to list oldtrafford 12 3,372 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  Using .append() with list vs dataframe Mark17 7 9,908 Jun-12-2022, 06:54 PM
Last Post: Mark17
  Replace elements of array with elements from another array based on a third array Cola_Reb 6 1,745 May-13-2022, 06:06 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020