Combinations or Permutations
ckaynor at zindagigames.com
Mon Sep 20 23:00:35 CEST 2010
The itertools module (http://docs.python.org/library/itertools.html) has
both permutations and combinations functionality.
On Mon, Sep 20, 2010 at 1: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:
> I am curious if there is an optimized way to generate this:
> I currently have an iteration that does this:
> from math import *
> for it1 in range(0 ,length):
> for it2 in range(it1+1, length):
> print list2
> However, this is one of the slowest parts of my function (beaten only
> by variable instantiation). I posted this on another forum looking to
> see if there was a different method completely. They said that my
> method was about as simple as it could get, but I might be able to
> find out how to optimize my code here.
> Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list