Python 编码对所有元素求和 n 次常数值
Python coding to sum a constant value to all elements n times
我有一个整数列表。我需要向列表中的所有元素添加 value
。
列表中的这个添加必须发生 n 次,我需要打印所有值
列表中有 x 个元素。所以我通常创建一个 x 数组和所有值为 n 的元素。尽管在 python?
中,但无法创建循环来执行该过程
像这样?
myList = [YOUR LIST]
newList = [x+123 for x in myList]
print(newList)
使用普通的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=' ')
我有一个整数列表。我需要向列表中的所有元素添加 value
。
列表中的这个添加必须发生 n 次,我需要打印所有值
列表中有 x 个元素。所以我通常创建一个 x 数组和所有值为 n 的元素。尽管在 python?
中,但无法创建循环来执行该过程像这样?
myList = [YOUR LIST]
newList = [x+123 for x in myList]
print(newList)
使用普通的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=' ')