how to append to a list twice?

Peter Otten __peter__ at web.de
Fri Apr 21 18:09:24 EDT 2006


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



More information about the Python-list mailing list