Re: Fast generation of permutations

2006-01-25 Thread Frode Øijord
Jack Diederich wrote: > You might want to look at a specific purpose library for poker hands: > http://pokersource.sourceforge.net/ Nah, evaluating the poker hands is the FUN part! I want to do that myself :) > If you really want to do combinations a C extension has already > been written (by m

Fast generation of permutations

2006-01-25 Thread Frode Øijord
Hi all, given a sequence of n elements i need to generate all possible permutations of length k <= n. I found an elegant way to do this recursively: def comb(items, n): if n==0: yield [] else: for i in xrange(len(items)): for cc in comb(items[i+1:],n-1):