Possible to return two lists from a list comprehension?

LarsVegas picture LarsVegas · May 7, 2012 · Viewed 19.8k times · Source

Is it possible to return two lists from a list comprehension? Well, this obviously doesn't work, but something like:

rr, tt = [i*10, i*12 for i in xrange(4)]

So rr and tt both are lists with the results from i*10 and i*12 respectively. Many thanks

Answer

jamylak picture jamylak · May 7, 2012
>>> rr,tt = zip(*[(i*10, i*12) for i in xrange(4)])
>>> rr
(0, 10, 20, 30)
>>> tt
(0, 12, 24, 36)