builtin functions for and and or?
Michael Hartl
mhartl at post.harvard.edu
Sun Feb 13 16:34:21 EST 2005
I warmly recommend downloading Peter Norvig's Python utilities file
(http://aima.cs.berkeley.edu/python/utils.py) and putting it on your
Python path. (E.g., in bash, put a line like
export PYTHONPATH="/path/to/utilities_directory"
in your .bashrc file.) The utils.py file defines many useful
functions, including the ones you want:
# def every(predicate, seq):
# """True if every element of seq satisfies predicate.
# Ex: every(callable, [min, max]) ==> 1; every(callable, [min, 3])
==> 0
# """
# for x in seq:
# if not predicate(x): return False
# return True
#
# def some(predicate, seq):
# """If some element x of seq satisfies predicate(x), return
predicate(x).
# Ex: some(callable, [min, 3]) ==> 1; some(callable, [2, 3]) ==> 0
# """
# for x in seq:
# px = predicate(x)
# if px: return px
# return False
Michael
--
Michael D. Hartl, Ph.D.
Chief Technology Officer
http://quarksports.com/
More information about the Python-list
mailing list