-1

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)

Red
  • 26,798
  • 7
  • 36
  • 58
Adam
  • 23
  • 4

2 Answers2

0

You can use this code snippet

def update(lst):
    nl=[]
    for i in lst:
        nl.append(i*2)
    return nl
theCoder
  • 34
  • 5
  • refer the comment of https://stackoverflow.com/users/3799759/samwise list1 = [i * 2 for i in list1] – theCoder Dec 07 '20 at 17:14
0

Use a list comprehension:

list1 = [0.75, 0.29, 0.3]
list1 = [i * 2 for i in list1]
Red
  • 26,798
  • 7
  • 36
  • 58