-1

example file (.csv): in row[0] there is "d e f b c c c a"

file=open("example_file.csv","r")

column=""

for row in file:
    if "a" or "b" or "c" in row[0]:
        column+=row 

I'm trying to figure out a way that if the file has a,b or c in the row it will print only the a's b's or c's

FATCAT47
  • 40
  • 10

1 Answers1

0

You can use the any function:

if (any(x in row[0] for x in ("a", "b", "c"))):
    column += row
Jan
  • 42,290
  • 8
  • 54
  • 79
  • Or `any(x in row[0] for x in 'abc')` – alec Mar 30 '20 at 06:40
  • @alec: I guess, `a`, `b` and `c` are only placeholders so iterating over a string does not make much sense. – Jan Mar 30 '20 at 07:13
  • I ended up using 3 if statements for "a" "b" and "c" separately. It was kinda time sensitive but thanks for all the answers. Im going to update my code with them – FATCAT47 Mar 31 '20 at 08:32