jazbees wrote:
On Apr 25, 12:11 pm, Duncan Booth <duncan.bo...@invalid.invalid>
wrote:
jazbees <jazb...@gmail.com> wrote:
hasvowels = lambda x:max([y in x for y in "aeiou"])
hasvowels("parsnips")
True
hasvowels("sfwdkj")
False
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"])

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

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to