I have an array with coins, e.g. (coins=[10, 50, 100]
) and an array of the quantities of each coin (e.g. quantity=[1, 2, 1]
). I want to generate a new list l
, which shows all coins I have (e.g l=[10, 50, 50, 100]
).
So far i have this, which does the trick:
coins=[i for s in [b*[a] for a,b in zip(coins,quantity)] for i in s]
Is there a better way to solve this in python, than to create a list of lists and then flatten it?