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 29 times
0

Chaitanya Lakhchaura
- 55
- 9
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
- 19,325
- 4
- 32
- 58