How to do this in Python...

Paul Rubin phr-n2003b at
Fri Jan 24 00:09:21 CET 2003

"Michael Tiller" <mtiller at> writes:
> match = re.match(pattern, string)
> if match:
>   // do something with match object
> -or-
> if re.match(pattern, string):
>     match = re.match(pattern, string)
> The first one seems unnecessarily verbose and the second one is inefficient.
> Are there any other options?

Tim Peters suggested one a few days ago:

   if [match for match in [re.match(pattern,string)]][0]:
        # do something with match object

More information about the Python-list mailing list