python 3.x - Multiple if conditions comparing to one -
searched around bit , can't find exact problem way want fix it.
what best way shorten if statement when having many conditions vs 1 check in python 3?
example:
if "a" in word or "b" in word or "c" in word etc...: *do this*
what more correct/shorter way this? not want loop through. (i.e. in whatever check if in whatever)
i've seen other examples like:
if {"a", "b", "c", etc...} in {word}: *do this*
or
if ("a" or "b" or "c" etc....) in word: *do this*
none of these work. please help!
you may use any
built-in function.
any(iterable)
return
true
if element of iterable true. if iterable empty, returnfalse
.
any(s in word s in {'a', 'b', 'c'})
Comments
Post a Comment