On Python Coolness
wingo: Your hack only works if input sequence holds boolean (or integers for that matter) only. Note that Iverson’s Convention only says that the a boolean
result is encoded as 0 or 1.
There is an elegant solution to your puzzle: use another
lambda to work around
and being syntactic:
all = lambda seq: reduce(lambda a, b: a and b, seq, True)
Moreover, unlike
the Iverson page you linked to claims, at least with Python 2.5, Python does not use Iversion, but does the Perl-style convention of returning the first operand that determined the outcome of the expression, taking the short-circuit rules in mind:
>>> "m" and "n"
'n'
>>> [] and True
[]
Labels: Iverson, python, wingo