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

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


"Caleb Hattingh" <caleb1 at telkomsa.net> 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']

or

>>> 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
-- 
berthold at xn--hllmanns-n4a.de / <http://höllmanns.de/>
bhoel at web.de                 / <http://starship.python.net/crew/bhoel/>



More information about the Python-list mailing list