diff options
author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2006-06-20 10:58:19 +0200 |
---|---|---|
committer | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> | 2006-06-20 10:58:19 +0200 |
commit | aafd84cd45312cd197afcb01ac4d605d52d1209f (patch) | |
tree | 346567fd1fbc51cdef8f7525f41fdd15d96d4cea /compat.py | |
parent | 9bf7768129e98d76aa87552844fe56a49a291bcf (diff) | |
download | logilab-common-aafd84cd45312cd197afcb01ac4d605d52d1209f.tar.gz |
adds any/all builtins
Diffstat (limited to 'compat.py')
-rw-r--r-- | compat.py | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -188,3 +188,28 @@ except NameError: l2 = list(l) l2.reverse() return l2 + +# Python2.5 builtins +try: + any = any + all = all +except NameError: + def any(iterable): + """any(iterable) -> bool + + Return True if bool(x) is True for any x in the iterable. + """ + for elt in iterable: + if bool(elt): + return True + return False + + def all(iterable): + """all(iterable) -> bool + + Return True if bool(x) is True for all values x in the iterable. + """ + for elt in iterable: + if not bool(elt): + return False + return True |