"""Python 2.5 future import That module try to provide part of the improvment of Python 2.5 in Python 2.4 see http://docs.python.org/dev/whatsnew/other-lang.html To use it >>> from python25 import * Author: Guillaume Bouchard License: Public domain """ from inspect import getargspec as _getargs def any(iterator): """returns True if any value returned by the iterator is true """ for i in iterator: if i is True: return True else: return False def all(iterator): """all() returns True only if all of the values returned by the iterator evaluate as being true """ for i in iterator: if i is False: return False else: return True def partial(func,*partial_args,**partial_kwargs): """Prefill some arguments of a function called The constructor for partial takes the arguments (function, arg1, arg2, ... kwarg1=value1, kwarg2=value2). The resulting object is callable, so you can just call it to invoke function with the filled-in arguments. see http://docs.python.org/dev/whatsnew/pep-309.html Be carefull with that function, the behavior seem look like Python 2.5 but i'm not sure of that. """ def _partial(*args,**kwargs): arguments_list = _getargs(func)[0] arguments = list(partial_args) del arguments_list[:len(partial_args)] args = list(args) for i in arguments_list: if i in partial_kwargs: arguments.append(partial_kwargs[i]) del partial_kwargs[i] else: try: arguments.append(args.pop(0)) except IndexError: # No more items in args break kwargs.update(partial_kwargs) return func(*arguments,**kwargs) return _partial def min(iterator,key=(lambda x:x)): """Return the smallest value in an iterator The optional key keywoard supplies a function that takes a single argument and is called for every value in the list; min() will return the element with the smallest return value from this function """ return __builtins__['min']((key(i) for i in iterator)) def max(iterator,key=(lambda x:x)): """Return the largest value in an iterator The optional key keywoard supplies a function that takes a single argument and is called for every value in the list; max() will return the element with the largest return value from this function """ return __builtins__['max']((key(i) for i in iterator))