title: Repeat numbers using itertools
body: <p>I was learning itertools and encountered an interesting problem.</p>
  
  <p>How to get the following result?</p>
  
  <pre><code>nums = [1,2,3,4]
  # logic:  i+1 th number is repeated i times.
            2 is repeated 1 times and 4 is repeated 3 times.
  
  required = [2,4,4,4] 
  
  </code></pre>
  
  <h1>My attempt</h1>
  
  <pre><code>import itertools
  
  nums = [1,2,3,4]
  nums[::2]  # [1,3]
  nums[1::2] # [2,4]
                * 2 is repeated 1 times
                  * 4 is repeated 3 times and makes [2,4,4,4]
  
  list(itertools.starmap(itertools.repeat, zip(nums[::2],nums[1::2])))
  
  Gives,
  [repeat(1, 2), repeat(3, 4)]
  
  How to get:
  required = [2,4,4,4]
  
  </code></pre>
  
  <h1>Required</h1>
  
  <pre><code>From: [1,2,3,4]
  To:   [2,4,4,4]
  
  We can use itertools, list comp and numpy.
  With emphasis on itertools, since I am learning itertools functions
  such as repeat, starmap and so on.
  </code></pre>