I have a list of elements in Python and need to assign a number to the entire list. In R
, I could simply do the assignment and R
would rep
that number the necessary number of times. In Python, is the easiest thing to do a list comprehension?
x = [1,2,3,4,5]
#want to assign 0 to every element, would like to do x[:] = 0 but this causes an error
x[:] = [0 for i in range(len(x))] #pretty long for such a simple operation