Creating combinations from a tuple
<p>I take the data from the database. From the database they come in the form of a tuple:</p>

<pre><code>[('test1', 'test12', 'test13', 'test14'),
('test21', 'test22', 'test23', 'test24'), 
('test31', 'test32', 'test33', 'test34'), 
('test41', 'test42', 'test43', 'test44'), 
('test51', 'test52', 'test53', 'test54'), 
('test61', 'test62', 'test63', 'test64'), 
('test71', 'test72', 'test73', 'test74'), 
('test81', 'test82', 'test83', 'test84'), 
('test91', 'test92', 'test93', 'test94'), 
('test11', 'test12', 'test13', 'test14')]
</code></pre>

<p>And that's what I want:
make combinations of these input... so the output I had a combination of 4 parameters (such as in example) and...</p>

<p><strong>1)</strong> most importantly, new combinations,the values were always in its place, i.e. if in the original combinations the values were index [1], this means that in the new combination, it should also be [1]...</p>

<p><strong>2)</strong> there are no duplicate combinations</p>

<p>As example:</p>

<p>I got tuple:</p>

<pre><code>[('test91', 'test92', 'test93', 'test94'), 
('test11', 'test12', 'test13', 'test14')]
</code></pre>

<p>And from this I got new combinations:</p>

<pre><code>[('test91', 'test12', 'test13', 'test14'), 
('test11', 'test92', 'test93', 'test94')]
</code></pre>

<p>Maybe it's possible to do using the method of pairwise or something else.
Help.</p>

<p>You need to use <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow"><code>product</code></a> method from builtin package <a href="https://docs.python.org/3/library/itertools.html#itertools" rel="nofollow"><code>itertools</code></a> which gives cartesian product of input iterables.</p>

<p>Here is code that do what you desire. 
<strong>But be careful</strong>, because huge list would produce a ton of combinations, try not to run out of memory.</p>

<pre><code>from itertools import product


data = [('test91', 'test92', 'test93', 'test94'), 
('test11', 'test12', 'test13', 'test14')]

b = list(zip(*a))  # making list of n-th elements
# b = [('test91', 'test11'),  &lt;- first elements
# ('test92', 'test12'),  &lt;- second elements
# ('test93', 'test13'),  &lt;- third elements
# ('test94', 'test14')]
variations = product(*b)
output = set(variations) - set(a)  # this is unique variations without input data
#  output = {('test11', 'test12', 'test13', 'test94'),
#  ('test11', 'test12', 'test93', 'test14'),
#  ('test11', 'test12', 'test93', 'test94'),
#  ('test11', 'test92', 'test13', 'test14'),
#  ('test11', 'test92', 'test13', 'test94'),
#  ('test11', 'test92', 'test93', 'test14'),
#  ('test11', 'test92', 'test93', 'test94'),
#  ('test91', 'test12', 'test13', 'test14'),
#  ('test91', 'test12', 'test13', 'test94'),
#  ('test91', 'test12', 'test93', 'test14'),
#  ('test91', 'test12', 'test93', 'test94'),
#  ('test91', 'test92', 'test13', 'test14'),
#  ('test91', 'test92', 'test13', 'test94'),
#  ('test91', 'test92', 'test93', 'test14')}
</code></pre>

<p>If you want output to be with input data you can simply </p>

<pre><code>output = set(variations)
</code></pre>

<p>If you need a list instead of set, just do</p>

<pre><code>output = list(output)
</code></pre>

python python-3.x combinations