"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
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
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
> >
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
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
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
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
[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
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
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
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
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.
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
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
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
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
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])
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
> 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:
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)
>
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
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):
> 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] -
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
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
"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
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
27 matches
Mail list logo