python - What is a good way to extend a list with a repeated number? -


i want extend list number 2450, 50 times. way this?

for e in range(0,50):     l2.extend(2450) 

this add 2450, 50 times. l2.extend([2450]*50)

example:

>>> l2 = [] >>> l2.extend([2450]*10) >>> l2 [2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450] 

or better yet:

>>> itertools import repeat >>> l2 = [] >>> l2.extend(repeat(2450,10)) >>> l2 [2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450] 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -