On Jul 4, 1:22 pm, bullockbefriending bard <[EMAIL PROTECTED]>
wrote:
> I was able to google a recipe for a k_permutations generator,  such
> that i can write:
>
> x = range(1, 4)  # (say)
> [combi for combi in k_permutations(x, 3)] =>
>
> [[1, 1, 1], [1, 1, 2], [1, 1, 3], [1, 2, 1], [1, 2, 2], [1, 2, 3], [1,
> 3, 1], [1, 3, 2], [1, 3, 3], [2, 1, 1], [2, 1, 2], [2, 1, 3], [2, 2,
> 1], [2, 2, 2], [2, 2, 3], [2, 3, 1], [2, 3, 2], [2, 3, 3], [3, 1, 1],
> [3, 1, 2], [3, 1, 3], [3, 2, 1], [3, 2, 2], [3, 2, 3], [3, 3, 1], [3,
> 3, 2], [3, 3, 3]]
>
> but what i really want is the above without repetition, i.e.:
>
> [combi for combi in k_permutations_without_repetitions(x, 3)] =>
>
> [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
>

See `kslice` function here:

http://gflanagan.net/site/python/utils/sequtils/

Regards

Gerard

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to