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

jazbees jazbees at
Mon Apr 27 03:43:56 CEST 2009

On Apr 25, 12:11 pm, Duncan Booth < at invalid.invalid>
> jazbees <jazb... at> 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.

> Anyway, it is probably clearer to use the builtin 'any' for code like this:
> >>> def hasvowels(s):
> ...     return any(v in s for v in "aeiou")

I wasn't aware of either "any" or "all".  Thanks for the info!
Unfortunately this recent project where I used "min" and "max" is
running on a system using Python 2.4, so "any" and "all" are not

> If you are doing a lot of this consider whether you might be better off
> using sets:
> >>> def found(x,y):
> ...    return bool(set(x).intersection(y))

I haven't used sets very much, but I'll definitely keep this in mind.

More information about the Python-list mailing list