how to append to a list twice?

Petr Prikryl prikryl at skil.cz
Mon Apr 24 09:22:07 EDT 2006


"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 xrange(N-1, -1, -1):
> >     append(tailer)
> >     append(tailer)
>
> But Now You've Violated The DRY Principle!!!

Do you mean the "three times -1" in the xrange arguments?  :-)

pepr





More information about the Python-list mailing list