- 1
how to multiply the element of list?
how can i multiply any element of list because a=[1,2,34,67] and i wrote there a=a*2 give a=[1,2,34,67,1,2,34,67] how i can get this output a=[2,4,68,134]
1 Respuesta
+ 5
This is the quickest code I could come up with.
a=[1,2,34,67]
for i in range(len(a)):
a[i]=a[i]*2
print(a)
# Output [2, 4, 68, 134]
I'll edit this answer if I can find a shorter way.
EDIT: This is the shorter way
a=[i*2 for i in [1,2,34,67]]
print(a)
# Output [2, 4, 68, 134]