multiply floats in a list in python

You can use a for loop to multiply each element of the list by your desired float value. Here's an example code:

main.py
my_list = [1.5, 2.0, 3.5, 4.0]
multiplier = 1.5

for i in range(len(my_list)):
    my_list[i] *= multiplier

print(my_list)
124 chars
8 lines

In this example, we have a list my_list which contains floats that we want to multiply by multiplier. The for loop iterates through each index of the list and updates the value at that index by multiplying it with the multiplier. Finally, we print the resulting list which has been element-wise multiplied by multiplier.

gistlibby LogSnag