How to match a string to pattern “Foo-Bar”, where Bar can be any element of a list? [closed]

I would do two lookups:

if x in L or f'foo-{x}' in L:

which may be significantly faster than

if any(x == y or f'foo-{x}' == y for x in L):

which is essentially what you were proposing.

Browse More Popular Posts

Leave a Comment