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. > 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 available. > 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. Thanks! -- http://mail.python.org/mailman/listinfo/python-list