0

I have an if statement that wants to check:

if c=="a" or c=="e" or c=="i" or c=="o" or c=="w":

Is there a way to write this more efficiently so that I don't have to repeat c=="x" so much. Something like if c=="a" or "e" or "i" or "o" or "w":

Coder91092
  • 27
  • 5

2 Answers2

2

how about

letters = ["a", "e", "i", "o", "w"]
if c in letters:
    foo
lnxkrnl
  • 109
  • 1
  • 1
  • 6
0

you can try any() and all() funcs. In your case

if any(c==l for l in ['a','e','o','w']):
    # do stuff