muth.code13
muth.code13

Reputation: 5

Python coding to sum a constant value to all elements n times

I have a list of integers. I need to add a value to all the elements in the the list. This addition on the list must happen n times and I need a print of all the values

I have x elements in the list. So i typically created a array of x and all the elements with value n. Unable to create a loop to execute the process though in python?

Upvotes: 0

Views: 1872

Answers (2)

ron_olo
ron_olo

Reputation: 146

Using normal forloop.

myList = [0, 12, 30, 32] #column A
for i in myList:
    holder = i
    temp_list=[i,]
    for x in range(10): #change range(10) to range(250)
        holder += 123
        temp_list.append(holder)
    #print(temp_list)
    print(*temp_list, sep='    ')

Upvotes: 1

wasif
wasif

Reputation: 15488

Like this?

myList = [YOUR LIST]
newList = [x+123 for x in myList]
print(newList)

Upvotes: 0

Related Questions