Pulling all n-sized combinations from a list

Jack Diederich jack at performancedrivers.com
Thu Feb 9 14:11:24 EST 2006


On Thu, Feb 09, 2006 at 10:23:12AM -0800, mensanator at aol.com wrote:
> Jack Diederich wrote:
> > On Wed, Feb 08, 2006 at 12:50:19PM -0800, Swroteb wrote:
> > > Hi there,
> > >
> > > I've got a reasonably sized list of objects that I'd like to pull out
> > > all combinations of five elements from.  Right now I have a way to do
> > > this that's quite slow, but manageable.  I know there must be a better
> > > way to do this, but I'm not sure what it is.  Here's what I've got so
> > > far:
> > >
> >
> > import probstat # http://probstat.sourceforge.net
> > for (a, b, c) in probstat.Combination(range(9), 3): # 0..9, pick 3
> >   print a, b, c
> >
> > It is a C extension that does permutations & combinations and is
> > about 10x faster than doing it in pure python [I'm the author].
> > It is also the 3rd result for "python combination" and 5th for
> > "python permutaiton" but every month someone posts to c.l.py asking
> > for something similar.  Go figure.
> 
> Did you ever figure that some people use Windows?

I don't have a windows dev box so I can't vouch for this binary but
a user sent me a windows .pyd yesterday.

http://jackdied.com/static/probstat.pyd

-jackdied



More information about the Python-list mailing list