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
Post a Comment