Combinations or Permutations

Ian Kelly ian.g.kelly at gmail.com
Mon Sep 20 23:02:33 CEST 2010


On Mon, Sep 20, 2010 at 2:54 PM, Seth Leija <fazzitron at gmail.com> wrote:

> I need to know how to generate a list of combinations/permutations
> (can't remember which it is). Say I have a list of variables:
>
> [a,b,c,d,...,x,y,z]
>
> I am curious if there is an optimized way to generate this:
>
> [[a,b],[a,c],[a,d],...,[x,z],[y,z]]
>

In Python 2.6 or newer:

>>> from itertools import combinations
>>> import string
>>> print list(combinations(string.lowercase, 2))

Cheers,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100920/5ea171a4/attachment.html>


More information about the Python-list mailing list