How can I multiply each element of a list by 10 | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

How can I multiply each element of a list by 10

Python

13th Oct 2021, 8:42 AM
Shobande Mayowa
3 Antworten
+ 7
You can just use a list comprehension: my_list = [1, 2, 3, 4, 5] my_new_list = [i * 5 for i in my_list] >>> print(my_new_list) [5, 10, 15, 20, 25]
13th Oct 2021, 8:48 AM
Cyber Nate
Cyber Nate - avatar
+ 5
n=[7,5,9] for i in range(len(n)): n[i]=n[i]*10 print(n[i]) #Like this you can
13th Oct 2021, 8:45 AM
Atul [Inactive]
+ 4
Another way by using map my_list = [1, 2, 3, 4, 5] print (list(map(lambda x:x*10,my_list ))) #output [10,20,30,40,50]
13th Oct 2021, 9:22 AM
Myo Thuzar
Myo Thuzar - avatar