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

Looks like there are itertools recipes for those, similar to what Michael just posted. Taken from here: http://docs.python.org/lib/itertools-recipes.html


def all(seq, pred=bool):
    "Returns True if pred(x) is True for every element in the iterable"
    for elem in ifilterfalse(pred, seq):
        return False
    return True

def any(seq, pred=bool):
"Returns True if pred(x) is True for at least one element in the iterable"
for elem in ifilter(pred, seq):
return True
return False



-- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list

Reply via email to