On 2006-05-02, Boris Borcic <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: >> On 2006-05-02, Boris Borcic <[EMAIL PROTECTED]> wrote: >>> Grant Edwards wrote: >>>> Python knows how to count. :) >>>> >>>> def countFalse(seq): >>>> return len([v for v in seq if not v]) >>>> >>>> def countTrue(seq): >>>> return len([v for v in seq if v]) >>>> >>>> def truth_test(seq): >>>> return countTrue(seq) == 1 >>>> >>> I'd suggest the more direct >>> >>> def countFalse(seq) : >>> return sum(1 for v in seq if not v) >> >> I guess I don't see how that is more direct. >> >> If you want to know how many items are in a seqneuce, you call >> len(). > > sum doesn't construct a sequence
Doh! I missed the fact that you used a generator rather than a list comprehension. >> Converting that list to a list of 1's > > that's not what my suggestion is doing I see that now. -- Grant Edwards grante Yow! Hey, waiter! I want at a NEW SHIRT and a PONY TAIL visi.com with lemon sauce! -- http://mail.python.org/mailman/listinfo/python-list