On 9 October 2012 13:55, Peter Otten __pete...@web.de wrote:
Duncan Booth wrote:
mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it?
My gut feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y =
On 9/10/12 04:39:28, rusi wrote:
On Oct 9, 7:34 am, rusi rustompm...@gmail.com wrote:
How about a 2-paren version?
x = [1,2,3]
reduce(operator.add, [['insert', a] for a in x])
['insert', 1, 'insert', 2, 'insert', 3]
Or if one prefers the different parens on the other side:
On 10/11/2012 6:21 PM, Hans Mulder wrote:
On 9/10/12 04:39:28, rusi wrote:
On Oct 9, 7:34 am, rusi rustompm...@gmail.com wrote:
How about a 2-paren version?
x = [1,2,3]
reduce(operator.add, [['insert', a] for a in x])
['insert', 1, 'insert', 2, 'insert', 3]
Or if one prefers the
On Fri, 12 Oct 2012 00:21:57 +0200, Hans Mulder wrote:
On 9/10/12 04:39:28, rusi wrote:
On Oct 9, 7:34 am, rusi rustompm...@gmail.com wrote:
How about a 2-paren version?
x = [1,2,3]
reduce(operator.add, [['insert', a] for a in x])
['insert', 1, 'insert', 2, 'insert', 3]
Or if one
mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it?
My gut feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
range(len(x y
['insertme',
On Mon, 08 Oct 2012 19:34:26 -0700, rusi wrote:
How about a 2-paren version?
x = [1,2,3]
reduce(operator.add, [['insert', a] for a in x])
['insert', 1, 'insert', 2, 'insert', 3]
That works, but all those list additions are going to be slow. It will be
an O(N**2) algorithm.
If you're
Duncan Booth wrote:
mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it?
My gut feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
On Monday, October 8, 2012 10:06:50 PM UTC-4, Roy Smith wrote:
In article mailman.1976.1349747963.27098.python-l...@python.org,
(big snip)
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
range(len(x
A statement ending in four close parens is usually
On Mon, Oct 8, 2012 at 1:28 PM, mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it? My gut
feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
On Mon, Oct 8, 2012 at 12:28 PM, mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it? My
gut feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i
On 2012-10-08 20:28, mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it? My gut
feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
On 8 October 2012 20:28, mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it? My
gut feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
On Mon, Oct 8, 2012 at 1:52 PM, Joshua Landau
joshua.landau...@gmail.com wrote:
But it's not far. I wouldn't use Ian Kelly's method (no offence), because of
len(x): it's less compatible with iterables. Others have ninja'd me with
good comments, too.
That's fair, I probably wouldn't use it
On 10/08/2012 09:45 PM, Chris Kaynor wrote:
[('insertme', i) for i in x]
This is not enough, you have to merge it afterwards.
y = [item for tup in y for item in tup]
--
http://mail.python.org/mailman/listinfo/python-list
mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it? My
gut feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
range(len(x y
['insertme',
Agon Hajdari wrote:
Sent: Monday, October 08, 2012 3:12 PM
To: python-list@python.org
Subject: Re: Insert item before each element of a list
On 10/08/2012 09:45 PM, Chris Kaynor wrote:
[('insertme', i) for i in x]
This is not enough, you have to merge it afterwards.
Why do you say
On 10/08/2012 11:15 PM, Prasad, Ramit wrote:
Agon Hajdari wrote:
Sent: Monday, October 08, 2012 3:12 PM
To: python-list@python.org
Subject: Re: Insert item before each element of a list
On 10/08/2012 09:45 PM, Chris Kaynor wrote:
[('insertme', i) for i in x]
This is not enough, you have
Agon Hajdari wrote:
On 10/08/2012 11:15 PM, Prasad, Ramit wrote:
Agon Hajdari wrote:
On 10/08/2012 09:45 PM, Chris Kaynor wrote:
[('insertme', i) for i in x]
This is not enough, you have to merge it afterwards.
Why do you say that? It seems to work just fine for me.
x
[0, 1,
mooremath...@gmail.com writes:
x = [1, 2, 3] ..
y
['insertme', 1, 'insertme', 2, 'insertme', 3]
def ix(prefix, x):
for a in x:
yield prefix
yield a
y = list(ix('insertme', x))
from itertools import *
y = list(chain.from_iterable(izip(repeat('insertme'), x)))
On Mon, 08 Oct 2012 12:28:43 -0700, mooremathewl wrote:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
range(len(x y
['insertme', 1, 'insertme', 2, 'insertme', 3]
[i for j in [1,2,3] for i in ('insertme', j)]
mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it?
My gut feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i
in range(len(x y
On 10/8/2012 3:28 PM, mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it? My gut
feeling is there is a better way than the following:
import itertools
x = [1, 2, 3]
y = list(itertools.chain.from_iterable(('insertme', x[i]) for i in
In article mailman.1976.1349747963.27098.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
On 10/8/2012 3:28 PM, mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it? My gut
feeling is there is a better way than the following:
On Oct 9, 7:06 am, Roy Smith r...@panix.com wrote:
In article mailman.1976.1349747963.27098.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
On 10/8/2012 3:28 PM, mooremath...@gmail.com wrote:
What's the best way to accomplish this? Am I over-complicating it? My
On Oct 9, 7:34 am, rusi rustompm...@gmail.com wrote:
How about a 2-paren version?
x = [1,2,3]
reduce(operator.add, [['insert', a] for a in x])
['insert', 1, 'insert', 2, 'insert', 3]
Or if one prefers the different parens on the other side:
reduce(operator.add, (['insert', a] for a in
On Oct 9, 12:06 pm, Roy Smith r...@panix.com wrote:
I'm going to go with this one. I think people tend to over-abuse list
comprehensions.
I weep whenever I find `_ = [...]` in other people's code.
--
http://mail.python.org/mailman/listinfo/python-list
26 matches
Mail list logo