[SciPy-User] all unique permutations

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Apr 28 21:12:42 EDT 2011


On Thu, Apr 28, 2011 at 8:59 PM, Peter Tittmann <ptittmann at gmail.com> wrote:
> Hi Josef,
> Not sure if this is relevant but i've used itertools.permutations
> (http://docs.python.org/library/itertools.html#itertools.permutations)

I didn't find any iterator that would give unique values

>>> for i in itertools.permutations([0,0,1]): print i
...
(0, 0, 1)
(0, 1, 0)
(0, 0, 1)
(0, 1, 0)
(1, 0, 0)
(1, 0, 0)

>>> for i in permit([0,0,1]): print i
...
[0, 0, 1]
[0, 1, 0]
[1, 0, 0]

Thanks for the pointer

Josef


> Best,
> Peter
> --
> Peter Tittmann
> c 707 849 4135
>
> On Thursday, April 28, 2011 at 5:40 PM, josef.pktd at gmail.com wrote:
>
> On Thu, Apr 28, 2011 at 8:27 PM, <josef.pktd at gmail.com> wrote:
>
> is there a copyright on basic algorithms ?
>
> from
> http://www.cut-the-knot.org/do_you_know/AllPerm.shtml
> I translated
> 2.Lexicographic order and finding the next permutation
>
> into python (because I couldn't get the matlab translation to work)
>
> looks useful for some permutation test
>
> some examples
>
> pprint(list(permit([1,1,1,1,0])))
>
> [[0, 1, 1, 1, 1],
>  [1, 0, 1, 1, 1],
>  [1, 1, 0, 1, 1],
>  [1, 1, 1, 0, 1],
>  [1, 1, 1, 1, 0]]
>
> for i in permit([1,0,1,0]): print i
>
> ...
> [0, 0, 1, 1]
> [0, 1, 0, 1]
> [0, 1, 1, 0]
> [1, 0, 0, 1]
> [1, 0, 1, 0]
> [1, 1, 0, 0]
>
> for i in permit([1,0,2,2]): print i
>
> ...
> [0, 1, 2, 2]
> [0, 2, 1, 2]
> [0, 2, 2, 1]
> [1, 0, 2, 2]
> [1, 2, 0, 2]
> [1, 2, 2, 0]
> [2, 0, 1, 2]
> [2, 0, 2, 1]
> [2, 1, 0, 2]
> [2, 1, 2, 0]
> [2, 2, 0, 1]
> [2, 2, 1, 0]
>
> for i in permit([1,3]): print i
>
> ...
> [1, 3]
> [3, 1]
>
> for i in permit([1,2.3]): print i
>
> ...
> [1, 2.2999999999999998]
> [2.2999999999999998, 1]
>
> for i in permit([1,2.5,3.5]): print i
>
> ...
> [1, 2.5, 3.5]
> [1, 3.5, 2.5]
> [2.5, 1, 3.5]
> [2.5, 3.5, 1]
> [3.5, 1, 2.5]
> [3.5, 2.5, 1]
>
> and
>
> for i in permit(['aa','bbb','c','aa']): print i
>
> ...
> ['aa', 'aa', 'bbb', 'c']
> ['aa', 'aa', 'c', 'bbb']
> ['aa', 'bbb', 'aa', 'c']
> ['aa', 'bbb', 'c', 'aa']
> ['aa', 'c', 'aa', 'bbb']
> ['aa', 'c', 'bbb', 'aa']
> ['bbb', 'aa', 'aa', 'c']
> ['bbb', 'aa', 'c', 'aa']
> ['bbb', 'c', 'aa', 'aa']
> ['c', 'aa', 'aa', 'bbb']
> ['c', 'aa', 'bbb', 'aa']
> ['c', 'bbb', 'aa', 'aa']
>
>
> Josef
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>



More information about the SciPy-User mailing list