Re: Combinations or Permutations

2010-09-21 Thread Raymond Hettinger
On Sep 20, 1:54 pm, Seth Leija 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]]

Re: Combinations or Permutations

2010-09-20 Thread Chris Kaynor
One of the advantages of using itertools is that it is written in C rather than Python (at least for CPython) and thus should run significantly faster than a pure Python implementation. Chris On Mon, Sep 20, 2010 at 4:21 PM, Dave Angel wrote: > On 2:59 PM, Seth Leija wrote: > >> I need to kno

Re: Combinations or Permutations

2010-09-20 Thread Dave Angel
On 2:59 PM, Seth Leija 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]] I currently have

Re: Combinations or Permutations

2010-09-20 Thread Seth Leija
On Sep 20, 3:08 pm, Mark Lawrence wrote: > On 20/09/2010 21:54, Seth Leija 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

Re: Combinations or Permutations

2010-09-20 Thread Mark Lawrence
On 20/09/2010 21:54, Seth Leija 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]] I current

Re: Combinations or Permutations

2010-09-20 Thread Ian Kelly
On Mon, Sep 20, 2010 at 2:54 PM, Seth Leija 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],..

Re: Combinations or Permutations

2010-09-20 Thread Chris Kaynor
The itertools module (http://docs.python.org/library/itertools.html) has both permutations and combinations functionality. Chris On Mon, Sep 20, 2010 at 1:54 PM, Seth Leija wrote: > I need to know how to generate a list of combinations/permutations > (can't remember which it is). Say I have a

Combinations or Permutations

2010-09-20 Thread Seth Leija
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]] I currently have an iteration that does this: #li