Talin wrote:
> I'm sure I am not the first person to do this, but I wanted to share
> this: a generator which returns all permutations of a list:
>
> def permute( lst ):
> if len( lst ) == 1:
> yield lst
> else:
> head = lst[:1]
> for x in permute( lst[1:] ):
>
On Mon, 15 Aug 2005, Matt Hammond wrote:
> Just satisfied my curiosity wrt this problem, so I might as well share :-)
>
def permute(list):
How about:
def permutation(l, i):
"Makes the ith permutation of the sequence l."
# leave out the reverses if you don't care about the or
Just satisfied my curiosity wrt this problem, so I might as well share :-)
>>> def permute(list):
... if len(list) <= 1:
... yield list
... else:
... for i in xrange(0,len(list)):
... for tail in permute( list[:i] + list[i+1:] ):
... yield [ list
"Casey Hawthorne" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's hard to make "complete" permutation generators, Knuth has a whole
> fascicle on it - "The Art of Computer Programming - Volume 4 Fascicle
> 2 - Generating All Tuples and Permutations" - 2005
Can you elaborate a
It's hard to make "complete" permutation generators, Knuth has a whole
fascicle on it - "The Art of Computer Programming - Volume 4 Fascicle
2 - Generating All Tuples and Permutations" - 2005
--
Regards,
Casey
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, Aug 12, 2005 at 03:48:38PM -0400, Michael J. Fromberger wrote:
> In article <[EMAIL PROTECTED]>,
> Talin <[EMAIL PROTECTED]> wrote:
>
> > I'm sure I am not the first person to do this, but I wanted to share
> > this: a generator which returns all permutations of a list:
>
> You're right
On Fri, 12 Aug 2005 12:39:08 -0700, Talin wrote:
> I'm sure I am not the first person to do this, but I wanted to share
> this: a generator which returns all permutations of a list:
>
> def permute( lst ):
> if len( lst ) == 1:
> yield lst
> else:
> head = lst[:1]
>
"Talin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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 [[]
Talin <[EMAIL PROTECTED]> writes:
> I'm sure I am not the first person to do this, but I wanted to share
> this: a generator which returns all permutations of a list:
>
> def permute( lst ):
> if len( lst ) == 1:
> yield lst
> else:
> head = lst[:1]
> for x in permu
In article <[EMAIL PROTECTED]>,
Talin <[EMAIL PROTECTED]> wrote:
> I'm sure I am not the first person to do this, but I wanted to share
> this: a generator which returns all permutations of a list:
>
> def permute( lst ):
> if len( lst ) == 1:
> yield lst
> else:
> head
10 matches
Mail list logo