Into itertools

Mark Dickinson dickinsm at gmail.com
Mon Apr 27 05:11:59 EDT 2009


On Apr 26, 5:32 pm, bearophileH... at lycos.com wrote:

> 3) xpairs(seq)

>     >>> list(xpairs(range(5)))
>     [(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3),
> (2, 4), (3, 4)]

Doesn't itertools.combinations already do this for you?

>>> list(itertools.combinations(range(5), 2))
[(0, 1), (0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (2,
4), (3, 4)]

Mark



More information about the Python-list mailing list