re.search over a list

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Thu Oct 23 12:28:27 EDT 2008


Steve Holden a écrit :
> Pat wrote:
>> Bruno Desthuilliers wrote:
(snip)
>>> words = ['foo', 'bar', 'somestring', 'baaz']
>>> re.search(r"^somestring$", "\n".join(words), re.MULTILINE)
(snip)
>>
> I suspect that
> 
>     any(re.match(pat, word) for word in words)
> 
> might be a more efficient way to do this.

Indeed. I'm not yet used to have all and any builtins, thanks for the 
reminder.



More information about the Python-list mailing list