How to do this in Python...

Simo Salminen look at sig.invalid
Fri Jan 24 01:48:14 CET 2003

* Paul Rubin [23 Jan 2003 15:09:21 -0800]
> Tim Peters suggested one a few days ago:
>    if [match for match in [re.match(pattern,string)]][0]:
>         # do something with match object

and from cookbook:

Not recommended, in any case, is the following abuse of list format
as comprehension

while [line for line in (file.readline(),) if line]:

It works, but it is unreadable and error-prone.


i think the conclusion applies to this case too.

simo <dot> salminen <at> iki <dot> fi

More information about the Python-list mailing list