A permutation on permutations
simonb at webone.com.au
simonb at webone.com.au
Sun Nov 25 07:48:53 EST 2001
well, i'd like to see this list comprehension
implemented properly ; it doesn't
compute as it stands (on 2.1.1)...?
But i understand the problem;
one way to solve it efficiently is
to choose one permutation out of the
reflected pair, as u build. Unfortunately,
this nice peice of list comprehensions
will (AFAICS) be disposed of.
To choose, eg. pick only perms
whos first entry is less than the last
:)
Simon B
Arthur Siegel wrote:
>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