On Apr 26, 11:32 am, bearophileh...@lycos.com wrote:
> Some idioms are so common that I think they deserve to be written in C
> into the itertools module.
>
> 1) leniter(iterator)
...
> 2) xpairwise(iterable)
...
> 3) xpairs(seq)
...
> 4) xsubsets(seq)
...

Good suggestions.  Another useful function I'd like to see in
itertools is the Cartesian product.  This can be implemented as:

def cartesian_product(*args):
    """Iterates over the Cartesian product of args[0], args[1], ..."""
    if not args:
        return
    elif len(args) == 1:
        for item in args[0]:
            yield (item,)
    else:
        for item in args[0]:
            for item2 in cartesian_product(*args[1:]):
                yield (item,) + item2
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to