On May 22, 7:21 pm, "Joel Koltner" <[EMAIL PROTECTED]>
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
Peter Otten <[EMAIL PROTECTED]> wrote:
> The speed gain is significant. Why should I throw away useful information if
> I have it?
My thinking was that it wasn't generic enough, and I was looking for a
solution that would work for more generic problem. I agree, I shouldn't
have used the world "e
Yves Dorfsman wrote:
> Peter Otten <[EMAIL PROTECTED]> wrote:
>
>> > A slightly similar problem: If I want to "merge," say, list1=[1,2,3]
>> > with list2=[4,5,6] to obtain [1,4,2,5,3,6], is there some clever way
>> > with "zip" to do so?
>
>> >>> items = [None] * 6
>> >>> items[::2] = 1,2,3
>> >
Peter Otten <[EMAIL PROTECTED]> wrote:
> > A slightly similar problem: If I want to "merge," say, list1=[1,2,3] with
> > list2=[4,5,6] to obtain [1,4,2,5,3,6], is there some clever way with "zip"
> > to do so?
> >>> items = [None] * 6
> >>> items[::2] = 1,2,3
> >>> items[1::2] = 4,5,6
> >>> items
Hi Marc,
"Marc Christiansen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm not sure I would recommend it, but try:
> [v for x in range(4) for v in (x, 2 * x)]
That certainly works... and it almost seems like a bit less of a hack (if
perhaps somewhat harder to read) than the
"inhahe" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> i figured out a solution
>
> sum([x,2*x] for x in range(4)],[]) #not tested
Nice... thanks; I probably had seen code using 'sum' to flatten but hadn't
actually understood how it worked. After playing around some it's now
cl
"Peter Otten" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>> A slightly similar problem: If I want to "merge," say, list1=[1,2,3] ...
items = [None] * 6
items[::2] = 1,2,3
items[1::2] = 4,5,6
items
> [1, 4, 2, 5, 3, 6]
Thanks Peter, that's pretty clean -- I lik
Joel Koltner <[EMAIL PROTECTED]> 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) ]
>
> ...and receive
>
> [ 0,0,1,2,2,4,3,6]
>
> ...but of cours
On Thu, 22 May 2008 15:29:42 -0400, inhahe wrote:
> "Joel Koltner" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> 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:
>>
>>
"Joel Koltner" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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) ]
>
> ...and receive
>
> [ 0,0
Joel Koltner 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) ]
>
> ...and receive
>
> [ 0,0,1,2,2,4,3,6]
>
> ...but of course you really get a
Joel Koltner 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) ]
...and receive
[ 0,0,1,2,2,4,3,6]
...but of course you really get a list of lists:
[[0, 0
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) ]
...and receive
[ 0,0,1,2,2,4,3,6]
...but of course you really get a list of lists:
[[0, 0], [1, 2], [2, 4], [3,
13 matches
Mail list logo