and [True,True] --> [True, True]?????

jazbees jazbees at gmail.com
Wed Apr 29 04:35:02 CEST 2009


On Apr 27, 1:10 pm, Terry Reedy <tjre... at udel.edu> wrote:
> The difference between
>
> hasvowels = lambda x:max([y in x for y in "aeiou"])
>
> and
>
> def hasvowels(x): return max([y in x for y in "aeiou"])
>
> is that the first is 4 chars shorter, but the result has a generic
> .__name__ attribute of '<lambda>' insteand of the specific 'hasvowels',
> which is definitely more useful.  Given this and the that the main
> purpose of lambda is to avoid a local name binding, many consider its
> use in 'name = lambda...' to be bad form.
>
> tjr

Point taken.  Thanks for the explanation, Terry!  Thanks also to John
for pointing out the execution speed difference when compared to
regular expressions.  I try as much as possible to experiment with
different variations for certain code blocks, but I still don't have
enough of the language in my head to think of all the possible
alternatives.  Those examples are great for oiling the mental
machine.  Cheers!

Justin



More information about the Python-list mailing list