Re: Permutation Generator



"Talin" <talin@xxxxxxx> wrote in message
news:mailman.3042.1123875574.10512.python-list@xxxxxxxxxxxxx
> I wanted to share
> this: a generator which returns all permutations of a list:


Try this instead:
def permuteg(lst): return ([lst[i]]+x
for i in range(len(lst))
for x in permute(lst[:i]+lst[i+1:])) \
or [[]]

Alan Isaac


.



Relevant Pages

  • Re: best cumulative sum
    ... But is a generator "better"? ... elif not iterable: ... Alan Isaac ... Prev by Date: ...
    (comp.lang.python)
  • Re: Use of random bits
    ... On the other hand the Mersenne Twister Random Number Generator used e.g., in SPSS, is considered a very good one for many purposes. ... will it be one chosen with equal probability from all permutations. ... end input program. ...
    (sci.stat.math)
  • Re: shuffling algorithm
    ... iteration, the random number generator is asked to pick an integer in. ... your algorithm is a mapping of a set of 27 equal probability items ... (the possible sequences of 3 numbers in generated by the random number ... generator) onto a set of 6 items (the possible permutations of 3 cards). ...
    (sci.crypt)
  • Re: Implementaion of random.shuffle
    ... permutations of x is larger than the period of most random number ... plus the state the generator it is in) before repeating. ... That's an example of the pigeonhole principle, one of the most simple yet ... powerful mathematical principles around. ...
    (comp.lang.python)
  • Re: Can random_shuffle be used to shuffle a deck of cards?
    ... 100 items (10^157 permutations), ... order to shuffle an array of 52 elements. ... a pseudorandom number generator: as the sequence of numbers output by ...
    (microsoft.public.vc.stl)