multiple variables in list comprehension? : <p>I want to create a list of lists from a list of multi-field strings and wonder if it is possible to do so in a comprehension.</p>

<p>Input:</p>

<pre><code>inputs = ["1, foo, bar", "2, tom, jerry"]
</code></pre>

<p>Desired output:</p>

<pre><code>[[1, "foo", "bar"], [2, "tom", "jerry"]]
</code></pre>

<p>Splitting the string in a comprehension is easy:</p>

<pre><code>&gt;&gt;&gt; [s.split(",") for s in inputs]
[['1', ' foo', ' bar'], ['2', ' tom', ' jerry']]
</code></pre>

<p>But I'm having trouble figuring out how to access the columns after the string has been split inside the comprehension, because it would seem to require a variable assignment.  The following are not valid Python, but illustrate what I'm looking for:</p>

<pre><code>[[int(x), y.strip(), z.strip() for x,y,z = s.split(",")] for s in inputs]
    or
[[int(v[0]), v[1].strip(), v[2].strip() for v = s.split(",")] for s in inputs]
</code></pre>

<p>Is there a way to assign variables inside a comprehension so that the output can be composed of functions of the variables?  A loop is trivial, but generating a list by transforming inputs sure seems like a "comprehension-ish" task.</p>

<pre><code>outputs = []
for s in inputs:
    x,y,z = s.split(",")
    outputs.append([int(x), y.strip(), z.strip()])
</code></pre>
