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
> >>>
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 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
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 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
On 9/10/12 04:39:28, rusi wrote:
> On Oct 9, 7:34 am, 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]
>
> Or if one prefers the different parens on the other side:
>
reduce
On Monday, October 8, 2012 10:06:50 PM UTC-4, Roy Smith wrote:
> In article ,
>
(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 going to be pretty
>
> difficult to figure
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]
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
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))
On Oct 9, 12:06 pm, Roy Smith 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
On Oct 9, 7:34 am, 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]
Or if one prefers the different parens on the other side:
>>> reduce(operator.add, (['insert', a] for a in x))
['i
On Oct 9, 7:06 am, Roy Smith wrote:
> In article ,
> Terry Reedy 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:
>
In article ,
Terry Reedy 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:
> >
> import itertools
> x = [1, 2, 3]
> y = list(itertoo
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
range(len(x)))
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
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 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'
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
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:
>>> [(
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 hav
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)))
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
On Mon, Oct 8, 2012 at 1:52 PM, Joshua Landau
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 either. It points to a
poss
On 8 October 2012 20:28, 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)
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
range(len(x
On Mon, Oct 8, 2012 at 12:28 PM, 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
> rang
On Mon, Oct 8, 2012 at 1:28 PM, 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
ran
26 matches
Mail list logo