A permutation on permutations
Arthur Siegel
ajs at ix.netcom.com
Sun Nov 25 01:18:28 EST 2001
What I've come up with is:
L is my list of arbitrary length.
M= [i for i in range (len(L))]
#thanks to Rainer Deyke's post
def perms(L):
if list == [] :
return [[]]
return [[list[i] + p for i in range(len(list))\
for p in perms(list[:i] + list[i+1:])]
def removedups(t):
for p in t:
m=copy.copy(p)
m.reverse()
if m in t:
t.remove(m)
def drawcurve(t):
#t is M or a slice of M
perm=perms(t)
removedups(perm)
for i in range(len(perm)):
cp=[L[j] for j in perm[i]]
BezierCurve(cp)
It seems to work.
But I wonder if there is a significantly more
efficient solution
Art
More information about the Python-list
mailing list