Changing Values in a list through Iteration of indexes

Опубликовано: 06 Октябрь 2024
на канале: Ralph Turchiano
143
like

Just a basic example of changing values in a list through Iteration of the indexes without creating a new list or appending. Python code below
#listmanipulation #index #value

alpha = [1,2,3,4,5,6,7,8,9,10,11]
List Manipulation and Iteration Example by Ralph Turchiano
def multiply(list1):
for index in range(len(list1)):
if index % 3 == 0 :
list1[index] *=2
if index % 7 == 0 :
list1[index] *=3
return list1

print(multiply(alpha))
print(alpha)
alpha == alpha