builtin functions for and and or?

Brian Beck exogen at gmail.com
Sun Feb 13 16:51:32 EST 2005


Roose wrote:
> I need this a lot: a one line way to do a n-ary and or 'or'.

Here's a one-liner for the n-ary and:

bool(min(bool(x) for x in L))


py> bool(min(bool(x) for x in [1, 1, 1, 0]))
False
py> bool(min(bool(x) for x in [1, 1, 1, 1]))
True
py> bool(min(bool(x) for x in ['a', '', 'b', 'c']))
False
py> bool(min(bool(x) for x in ['a', 'b', 'c', 'd']))
True

--
Brian Beck
Adventurer of the First Order



More information about the Python-list mailing list