and [True,True] --> [True, True]?????
tjreedy at udel.edu
Mon Apr 27 20:10:44 CEST 2009
> On Apr 25, 12:11 pm, Duncan Booth <duncan.bo... at invalid.invalid>
>> jazbees <jazb... at gmail.com> wrote:
>>>>>> hasvowels = lambda x:max([y in x for y in "aeiou"])
>> Do you object to using def to define functions?
> Not at all. Do you object to my use of lambdas? I'm not aware of
> anything that says it's bad form to define a function using a lambda
> when the only thing that a function does is immediately return some
> calculated value.
The difference between
hasvowels = lambda x:max([y in x for y in "aeiou"])
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.
More information about the Python-list