Replacing words from strings except 'and' / 'or' / 'and not'

Berthold Höllmann bhoel at
Thu Nov 25 22:51:13 CET 2004

"Caleb Hattingh" <caleb1 at> writes:

> Wow, yeh, that's actually much better.
> I got into python back when map, filter & lambda were still

Me too, but I always try to use some of this newfangled stuff, and
sometimes it is helpful ;-)

> fashionable.   The list comprehension is sweeter than the map, that's
> for sure.

But a shorter solution was always(TM) avaliable

>>> ans = map(lambda w, k=keywords : myfunc(k, w), lsen)
>>> ans
['hi', 'there', '*my*', 'name', '*is*', 'caleb']


>>> map(lambda w: myfunc(keywords, w), lsen)
['hi', 'there', '*my*', 'name', '*is*', 'caleb']

But I think the last one only with the newer Pythons.

Kind Regards
berthold at / <http://hö>
bhoel at                 / <>

More information about the Python-list mailing list