I have an array
a. I want to create new array with doubled size where items is x*2 and x*3.
a = [1,10,100] result must be
b = [2,3,20,30,200,300]
I know this (ugly and very slow) way:
b = sum([[x*2,x*3] for x in a], )
There is other way (truly I want shortest way :)?
This can be done using a list comprehension with nested loops
In : [y for x in a for y in (x * 2, x * 3)] Out: [2, 3, 20, 30, 200, 300]
Seems to outperform all answers, but loses to the
numpy solution when
a is large.