Python: Converting a queryset in a list of tuples
<p>i want to turn a queryset into a list of tuples. "result" ist what it should look like:</p>

<pre><code>queryset = [{x:'1',y:'a'}, {x:'2',y:'b'}]
result = [(1,'a'),(2,'b')]
</code></pre>

<p>So the solution i do have right now is this one, but it seems to me that there could be a way to shorten the code, and make it more efficient. Is there a way?</p>

<p>My current solution:</p>

<pre><code>result = []
for dic in queryset:
    result.append((dic[x],dic[y]))
</code></pre>

<p>Assuming <code>queryset</code> is supposed to look like this, with <code>'x'</code> and <code>'y'</code> as string keys:</p>

<pre><code>&gt;&gt;&gt; queryset = [{'x':'1', 'y':'a'}, {'x':'2', 'y':'b'}]
&gt;&gt;&gt; result = [(q['x'], q['y']) for q in queryset]
&gt;&gt;&gt; result
[('1', 'a'), ('2', 'b')]
&gt;&gt;&gt; # or if x and y are actually the correct names/vars for the keys
... result = [(q[x], q[y]) for q in queryset]
</code></pre>

python django performance