I have a code in which there is a lineif y in x or f in x or h in x and so on. Even if it works, it seems to be very long.
I tried if (y or f or h) in x and if [y,f,h]in x but nothing worked.
Can anyone help?
Asked
Active
Viewed 27 times
0
Chaitanya Lakhchaura
- 43
- 8
1 Answers
0
Use any along with a generator expression:
y = 'y'
f = 'f'
x = 'x'
print(any(char in 'abcdex' for char in [y, f, x]))
Output:
True
gmds
- 17,927
- 4
- 26
- 51