I have often found a need to test substring matching for multiple candidates. I don’t think the proposed syntax is the best solution, but I think there’s something there.
Not related to the proposal, there’s an optimisation to your second example: skipping the list creation
any((i in 'ab') for i in ('c', 'a'))
For large iterables (('c', 'a') in this example), this means both not constructing and storing a large list (of boolean values), but also ending the iteration on the first true value found.
yes that is a bit confusing, one solution is to make it a new object type, just like there is list_iterator, set_iterator, maybe ('c' | 'a') could return an object of type str_lookup.
I am investigating if it could be useful in some other place apart from the in scenario, but in my opinion, the substring search on its own is a pretty common use case in support of this change.
alongside one another way to achieve this is by using,
import re
if re.search('c|a', 'ab'):
print(1)
where again the pipe operator is used to search the presence of any of these strings inside of re.search.
I would prefer to achieve the same without using the regex module.