Recursive function to develop permutations

Jack Diederich jack at performancedrivers.com
Tue Oct 19 12:52:52 EDT 2004


On Tue, Oct 19, 2004 at 12:34:57AM +0000, Steve Goldman wrote:
> Hi,
> 
> I am trying to come up with a way to develop all n-length permutations of a
> given list of values.  The short function below seems to work, but I can't
> help thinking there's a better way.  Not being a computer scientist, I find
> recursive functions to be frightening and unnatural.  I'd appreciate if
> anyone can tell me the pythonic idiom to accomplish this.
> 
> ###START CODE###
[snip]

Combinatorics (permutations, combinations, etc) get golfed (shortest/fastest)
on c.l.py a couple times a year.  Check groups.google.com for some solutions.
If you want fast, try probstat.sf.net which does some combinatorics in C with
a python wrapper.  disclosure: I wrote it.

-Jack



More information about the Python-list mailing list