For example, I have the list:
list1[]= [0.75, 0.29, 0.3]
And i want to create a function that goes through each element and multiplies them by 2 and updates the list (or saves it as a new list)
For example, I have the list:
list1[]= [0.75, 0.29, 0.3]
And i want to create a function that goes through each element and multiplies them by 2 and updates the list (or saves it as a new list)
You can use this code snippet
def update(lst):
nl=[]
for i in lst:
nl.append(i*2)
return nl
Use a list comprehension:
list1 = [0.75, 0.29, 0.3]
list1 = [i * 2 for i in list1]