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 need a container, which holds your tuples. You are thinking of list or scheme like tuples, which are linked lists. The tuples in python are expensive in creating, joining and appending. You should use lists for this purposes. You can take an list and just join it.</p>

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

<p>Or you can join your tuples outsite your gen function.</p>

<pre><code>def tuple_gen(x, y, num):
    for i in range(num):
        x += 1
        yield (x,y)

x = []
for i in tuple_gen(0,1,5):
    x.append(i)

for i in tuple_gen(0,2,6):
    x.append(i)
</code></pre>

<p>There are other container for python - even a linked list. Almost all are implemented as a list with some additionals.</p>

python arrays list tuples unpack