Generating all possible combination of elements in a list

Paul Rubin http
Mon Jul 24 06:17:38 EDT 2006


"Mir Nazim" <mirnazim at gmail.com> writes:
> Now I ahave a lits with 1060 lists in it. Now comes the hard part.
> How many possible distinct ways are there to arrange 1060 elements
> taken 96 at a time
> 
> 1060! / (1060 - 96)!

More than you want to think about:

    import math

    def logf(n):
        """return base-10 logarithm of (n factorial)"""
        f = 0.0 
        for x in xrange(1,n+1):
            f += math.log(x, 10)
        return f

    print logf(1060) - logf(1060 - 96)

Of course there are other ways you can calculate it, e.g.

   http://en.wikipedia.org/wiki/Stirlings_approximation



More information about the Python-list mailing list