I'm trying to figure out the solution to this particular challenge and so far I'm stumped.
Basically, what I'm looking to do is:
There is always
str.__contains__ if it's needed as a function somewhere:
In : str.__contains__('**foo**', 'foo') Out: True
This could be used for things like
The much more common usecase is to assign a truth value for each element in a list using a comprehension. Then we can make use of the
in keyword in Python:
In: ['foo' in x for x in ['**foo**','abc']] Out: [True, False]
The latter should always be preferred. There are edge cases where only a function might be possible.
But even then you could pass a lambda and use the statement:
sorted(some_list, key=lambda x: 'foo' in x)