How to multiply ints into list of lists

Viewed 18

I have list of lists -

list_1 = [[2,2],[3,4],[4,5],[2,1]

i want to multiply the list with x = 2

output will be:

list_1 =[[4,4],[6,8],[8,10],[4,2]]

thanks!

1 Answers

Try this one:

list_1 = [[2,2],[3,4],[4,5],[2,1]]
x = 2

[[elem*x for elem in l] for l in list_1]
>>>
[[4, 4], [6, 8], [8, 10], [4, 2]]
Related