Python. Find all possible combinations of numbers with set length
<p>I have a list of numbers: [0, 0, 1, 1, 2, 2]</p>

<p>I want to have all combinations of 2 numbers, I tried to do it with itertools:</p>

<pre><code>import itertools
a = [0, 0, 1, 1, 2, 2]
combinations = set(itertools.permutations(a, 2))
print(combinations)
# {(0, 1), (1, 2), (0, 0), (2, 1), (2, 0), (1, 1), (2, 2), (1, 0), (0, 2)}
</code></pre>

<p>I want to use all numbers in list to combinations, but itertools didn't do it.</p>

<p>So, I want to get result like this:</p>

<pre><code>(0, 0), (0, 1), (0, 1), (1, 0), (1, 0) ...
</code></pre>

<p>So, since we have two 0 and two 1 we will have two (0, 1) combinations and etc.</p>

<p>A set is a data structure without duplicates. Use a list:</p>

<pre><code>import itertools
a = [0, 0, 1, 1, 2, 2]
combinations = list(itertools.permutations(a, 2))
print(combinations)
</code></pre>

python algorithm combinations