Re: how to append to a list twice?

2006-04-24 Thread Petr Prikryl
"Fredrik Lundh" wrote: > Alex Martelli wrote: > > > > But of course that only does it once, and I don't want to have to copy > > > and paste the append line. Perhaps there's a better way than this. > > > > def makeseries(N): > > series = [N] > > append = series.append > > for tailer in xrang

Re: how to append to a list twice?

2006-04-22 Thread Fredrik Lundh
Alex Martelli wrote: > > But Now You've Violated The DRY Principle!!! > > Just as with any other unrolled loop, yes -- loop unrolling is an > optimization which is based exactly on exchanging some textual > repetition for a tiny bit more speed. I had hoped that the Unusual Capitalization would ha

Re: how to append to a list twice?

2006-04-21 Thread Alex Martelli
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > > > But of course that only does it once, and I don't want to have to copy > > > and paste the append line. Perhaps there's a better way than this. > > > > def makeseries(N): > > series = [N] > > append = series.append > >

Re: how to append to a list twice?

2006-04-21 Thread Peter Otten
John Salerno wrote: > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > (where each item is repeated twice after the first one), how might I do > that most efficiently? series = [100]*21 series[1::2] = series[2::2] = range(99, 89, -1) :-) Peter -- http://mail.python.org

Re: how to append to a list twice?

2006-04-21 Thread Gerard Flanagan
John Salerno wrote: > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > (where each item is repeated twice after the first one), how might I do > that most efficiently? > > Right now I have this: > > series = [100] > for x in range(10): # just for testing > series.app

Re: how to append to a list twice?

2006-04-21 Thread Dave Hansen
On 21 Apr 2006 12:50:38 -0700 in comp.lang.python, [EMAIL PROTECTED] wrote: >I don't get it (the Elliot solution)... How is it that the first value >is repeated once times, and the remaining values are repeated twice >times? Integer division truncates. 200/2 -> 100, 199/2 -> 99, 198/2 -> 99, etc

Re: how to append to a list twice?

2006-04-21 Thread John Salerno
John Salerno wrote: > [EMAIL PROTECTED] wrote: >> I don't get it (the Elliot solution)... How is it that the first value >> is repeated once times, and the remaining values are repeated twice >> times? >> > > Because of the way division works. The first number in the range is 200, > and 200/2 is

Re: how to append to a list twice?

2006-04-21 Thread John Salerno
[EMAIL PROTECTED] wrote: > I don't get it (the Elliot solution)... How is it that the first value > is repeated once times, and the remaining values are repeated twice > times? > Because of the way division works. The first number in the range is 200, and 200/2 is 100. The next number is 199, an

Re: how to append to a list twice?

2006-04-21 Thread callmebill
I don't get it (the Elliot solution)... How is it that the first value is repeated once times, and the remaining values are repeated twice times? -- http://mail.python.org/mailman/listinfo/python-list

Re: how to append to a list twice?

2006-04-21 Thread Edward Elliott
Nick Craig-Wood wrote: > That should be > > series = [x//2 for x in range(200, 1, -1)] > > to be "from __future__ import division" safe from __present__ import gratitude -- http://mail.python.org/mailman/listinfo/python-list

Re: how to append to a list twice?

2006-04-21 Thread Nick Craig-Wood
Edward Elliott <[EMAIL PROTECTED]> wrote: > John Salerno wrote: > > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > > (where each item is repeated twice after the first one), how might I do > > that most efficiently? > > Why not just this: > > series = [x/2 for x i

Re: how to append to a list twice?

2006-04-21 Thread James Stroud
John Salerno wrote: > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > (where each item is repeated twice after the first one), how might I do > that most efficiently? > > Right now I have this: > > series = [100] > for x in range(10): # just for testing > series.

Re: how to append to a list twice?

2006-04-21 Thread John Salerno
Edward Elliott wrote: > John Salerno wrote: > > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > > (where each item is repeated twice after the first one), how might I do > > that most efficiently? > > Why not just this: > > series = [x/2 for x in range(200, 1, -1)] c

Re: how to append to a list twice?

2006-04-21 Thread Gerard Flanagan
Gerard Flanagan wrote: > Gerard Flanagan wrote: > > John Salerno wrote: > > > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > > > (where each item is repeated twice after the first one), how might I do > > > that most efficiently? > > > > series = [100] > > > > for i in ra

Re: how to append to a list twice?

2006-04-21 Thread Edward Elliott
John Salerno wrote: > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > (where each item is repeated twice after the first one), how might I do > that most efficiently? Why not just this: series = [x/2 for x in range(200, 1, -1)] -- http://mail.python.org/mailman/listi

Re: how to append to a list twice?

2006-04-21 Thread Sion Arrowsmith
John Salerno <[EMAIL PROTECTED]> wrote: >If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] >(where each item is repeated twice after the first one), how might I do >that most efficiently? > >Right now I have this: > >series = [100] >for x in range(10): # just for testing

Re: how to append to a list twice?

2006-04-21 Thread Sybren Stuvel
John Salerno enlightened us with: > Interesting. I tried the *2 method twice, but I kept getting weird > results, I guess because I was using append and not extend. I > thought extend added lists to lists, but obviously that's not the > case here. [100].extend([90]) -> [100, 90] [100].append([90])

Re: how to append to a list twice?

2006-04-21 Thread Gerard Flanagan
Gerard Flanagan wrote: > John Salerno wrote: > > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > > (where each item is repeated twice after the first one), how might I do > > that most efficiently? > > series = [100] > > for i in range(1,10): > series.extend([100-i]*2

Re: how to append to a list twice?

2006-04-21 Thread Tim Chase
> Interesting. I tried the *2 method twice, but I kept > getting weird results, I guess because I was using append > and not extend. I thought extend added lists to lists, > but obviously that's not the case here. In the above example, it *is* "add[ing] lists to lists". Note the set of brackets:

Re: how to append to a list twice?

2006-04-21 Thread Fredrik Lundh
Alex Martelli wrote: > > But of course that only does it once, and I don't want to have to copy > > and paste the append line. Perhaps there's a better way than this. > > def makeseries(N): > series = [N] > append = series.append > for tailer in xrange(N-1, -1, -1): > append(tailer) >

Re: how to append to a list twice?

2006-04-21 Thread John Salerno
Paul McGuire wrote: > "John Salerno" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] >> (where each item is repeated twice after the first one), how might I do >> that most efficiently? >> >> Right now I have t

Re: how to append to a list twice?

2006-04-21 Thread [EMAIL PROTECTED]
Not sure if this is simpler or better, but here's a way to do it with a generator: value = 100 count = 0 def valueGen(): global value global count while(value >= 0): if(value == 100): yield value value -= 1 else: if(count & 1):

Re: how to append to a list twice?

2006-04-21 Thread Tim Chase
> If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > (where each item is repeated twice after the first one), how might I do > that most efficiently? > > Right now I have this: > > series = [100] > for x in range(10): # just for testing > series.append(series[-1] -

Re: how to append to a list twice?

2006-04-21 Thread Alex Martelli
John Salerno <[EMAIL PROTECTED]> wrote: > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > (where each item is repeated twice after the first one), how might I do > that most efficiently? > > Right now I have this: > > series = [100] > for x in range(10): # just for te

Re: how to append to a list twice?

2006-04-21 Thread Gerard Flanagan
John Salerno wrote: > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > (where each item is repeated twice after the first one), how might I do > that most efficiently? > > Right now I have this: > > series = [100] > for x in range(10): # just for testing > series.ap

Re: how to append to a list twice?

2006-04-21 Thread Paul McGuire
"John Salerno" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] > (where each item is repeated twice after the first one), how might I do > that most efficiently? > > Right now I have this: > > series = [100] > for

how to append to a list twice?

2006-04-21 Thread John Salerno
If I want to create a list of the form [100, 99, 99, 98, 98, 97, 97...] (where each item is repeated twice after the first one), how might I do that most efficiently? Right now I have this: series = [100] for x in range(10): # just for testing series.append(series[-1] - 1) But of course