Edit: I confused the difference between permutations and combinations. Edited the question just to keep it up (as I can't delete it). Though I realized my mistake.
I've been browsing this question around for a bit and I couldn't find a solution that fits uniquely to what I'm looking for.
The basic concept is if I ran a function gen_permutations([1,2])
to generate permutations. I would get the result ([1,2],[2,1])
, though in this result, I would classify they are the same set.
I would think of checking something as result[0] < result[1]
then add it to the set of results. Though, how would this be scaled up for example gen_permutations(input, size=n | n <= len(input))
?
Sorry if there's a question answered to this, but all "Similar Questions" point me to just "unique results" where [1,2] != [2,1].
Edit: Case for confusion, the function gen_permutations
is just a generic generator that I found and used here How to generate all permutations of a list in Python
Another example to make it bigger. I could run this case
for i in permutations([1,2,3,4],3):
print i
Gets the result
(1, 2, 3), (1, 2, 4),(1, 3, 2),(1, 3, 4),(1, 4, 2),(1, 4, 3),(2, 1, 3),(2, 1, 4),(2, 3, 1),(2, 3, 4),(2, 4, 1),(2, 4, 3),(3, 1, 2),(3, 1, 4),(3, 2, 1),(3, 2, 4),(3, 4, 1),(3, 4, 2),(4, 1, 2),(4, 1, 3),(4, 2, 1),(4, 2, 3),(4, 3, 1),(4, 3, 2)
Though (1,2,3)
and (3,2,1)
I would consider not unique. Since if you reordered them they would be the same set. I need help to code a generator of permutations that would not generate the result (3,2,1)
as (1,2,3)
was already generated.