[Python-Dev] product()
Guido van Rossum
guido at python.org
Sat Oct 25 17:14:32 EDT 2003
More information about the Python-Dev mailing list
Sat Oct 25 17:14:32 EDT 2003
- Previous message: [Python-Dev] product()
- Next message: [Python-Dev] product()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> it might be "alltrue" and "anytrue" -- the short-circuiting ones, > returning the first true or false item found respectively, as in: > > def alltrue(seq): > for x in seq: > if not x: return x > else: > return True > > def anytrue(seq): > for x in seq: > if x: return x > else: > return False > > these seem MUCH more generally useful than 'product' (but, > I still opine, not quite enough to warrant being built-ins). These are close to what ABC does with quantifiers. There, you can write IF EACH x IN sequence HAS x > 0: ... ABC has the additional quirk that if there's an ELSE branch, you can use x in it (as a "counter-example"). In Python, you could write this as if alltrue(x > 0 for x in sequence): ... but the current design doesn't expose x to the else branch. --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] product()
- Next message: [Python-Dev] product()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list