Python generate and return tuples in a non-list form
<pre><code>def tuple_gen(x, y, num):
    pos = []
    for i in range(num):
        x += 1
        pos.append([x, y])
        pos[i] = tuple(pos[i])
    return pos
</code></pre>

<p>my input is:</p>

<pre><code>&gt;&gt;&gt; tuple_gen(0,1,5)
[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1)]
</code></pre>

<p>What I want is to return tuples but not a list:</p>

<pre><code>&gt;&gt;&gt; tuple_gen(0,1,5)
(1, 1), (2, 1), (3, 1), (4, 1), (5, 1)
</code></pre>

<p>Because I want to form a list that includes different kind of tuples:</p>

<pre><code>&gt;&gt;&gt; [tuple_gen(0,1,5), tuple_gen(0,2,6)]
[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2)]
</code></pre>

<p>I want a short and clearest solution.</p>

<p>*note that I don't want to use any <code>extend</code> or <code>append</code> to merge those lists because I need so many tuples</p>

<p>You are currently returning a list of tuples:</p>

<pre><code>&gt;&gt;&gt; tuple_gen(0,1,5)
[(1, 1), (2, 1), (3, 1), (4, 1), (5, 1)]
</code></pre>

<p>You could return a tuple of tuples with <code>return tuple(pos)</code>.</p>

<p>That is what you asked for, but it won't help you for this use case:</p>

<pre><code>[tuple_gen(0,1,5), tuple_gen(0,2,6)]
</code></pre>

<p>That will still be a list of two tuples of tuples.</p>

<p>What you really need is to return a list, as you do, and then concatenate those lists later:</p>

<pre><code>tuple_gen(0,1,5) + tuple_gen(0,2,6)
</code></pre>

python arrays list tuples unpack