python list comprehension to create repeated value from the list
<p>I am trying to create </p>

<pre><code>[ x 
 for x in [1,2,3] 
     for y in [3,1,4] ]
</code></pre>

<p>Output:</p>

<pre><code>[1, 1, 1, 2, 2, 2, 3, 3, 3]
</code></pre>

<p>but what I want is to create </p>

<ul>
<li>1 3 times </li>
<li>2 1 times </li>
<li>3 4 times</li>
</ul>

<p><strong>Expected Output:</strong> </p>

<pre><code>[1, 1, 1, 2, 3, 3, 3, 3]
</code></pre>

<p>Is it possible to do this in list comprehension ? </p>

<p>Use the <a href="https://docs.python.org/3/library/functions.html#zip"><code>zip()</code> function</a> to pair up your numbers with their counts:</p>

<pre><code>numbers = [1, 2, 3]
counts = [3, 1, 4]
output = [n for n, c in zip(numbers, counts) for _ in range(c)]
</code></pre>

python list