Reputation: 19
I want to extend a list with the number 2450, 50 times. What is a good way to do this?
for e in range(0,50):
L2.extend(2450)
Upvotes: 0
Views: 83
Reputation: 7944
This will 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:
>>> from itertools import repeat
>>> l2 = []
>>> l2.extend(repeat(2450,10))
>>> l2
[2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450, 2450]
Upvotes: 9