Q:

Repeat elements of list python

I have a list of floats and want to multiply each value by a number. Code will explain it better:
list = [1.0,2.0,3.0]

and now I want to do an operation so that:
list =[1.0,1.0,1.0,2.0,2.0,2.0,3.0,3.0,3.0]

so for example multiply each value by 3 in the way shown.
Unfortunately I don't have a clue how to do that.

A:

Using list comprehension:
>>> lst = [1.0, 2.0, 3.0]
>>> [x for x in lst for i in range(3)]
[1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0]

BTW, don't use list as a variable name. It shadows builtin function list.

