Producing multiple items in a list comprehension

Paul Hankin paul.hankin at gmail.com
Fri May 23 11:33:56 EDT 2008


On May 22, 7:21 pm, "Joel Koltner" <zapwireDASHgro... at yahoo.com>
wrote:
> Is there an easy way to get a list comprehension to produce a flat list of,
> say, [x,2*x] for each input argument?
>
> E.g., I'd like to do something like:
>
> [ [x,2*x] for x in range(4) ]

[x * i for x in xrange(4) for i in xrange(1, 3)]

--
Paul Hankin



More information about the Python-list mailing list