title: Find combinations with arrays and a combination pattern
body: <p>I have arrays such as these, and each pattern designates a combination shape with each number representing the size of the combination.</p>
  
  <ul>
  <li>pattern 0: <code>[1, 1, 1, 1]</code></li>
  <li>pattern 1: <code>[2, 1, 1]</code></li>
  <li>pattern 2: <code>[3, 1]</code></li>
  <li>pattern 3: <code>[4]</code></li>
  <li>...</li>
  </ul>
  
  <p>I also have a char-valued list like below. len(chars) equals the sum of the upper array's value.</p>
  
  <p><code>chars = ['A', 'B', 'C', 'D']</code></p>
  
  <p>I want to find all combinations of chars following a given pattern. For example, for pattern 1, 4C2 * 2C1 * 1C1 is the number of combinations.</p>
  
  <pre><code>[['A', 'B'], ['C'], ['D']]
  [['A', 'B'], ['D'], ['C']]
  [['A', 'C'], ['B'], ['D']]
  [['A', 'C'], ['D'], ['B']]
  [['A', 'D'], ['B'], ['C']]
  [['A', 'D'], ['C'], ['B']]
  ...
  </code></pre>
  
  <p>But I don't know how to create such combination arrays. Of course I know there are a lot of useful functions for combinations in python. But I don't know how to use them to create a combination array of combinations.</p>
  
  <p><strong>EDITED</strong></p>
  
  <p>I'm so sorry my explanation is confusing. I show a simple example.</p>
  
  <ul>
  <li>pattern 0: <code>[1, 1]</code></li>
  <li>pattern 1: <code>[2]</code></li>
  <li><code>chars = ['A', 'B']</code></li>
  </ul>
  
  <p>Then, the result should be like below. So first dimension should be permutation, but second dimension should be combination.</p>
  
  <ul>
  <li>pat0: <code>[['A'], ['B']]</code></li>
  <li>pat0: <code>[['B'], ['A']]</code></li>
  <li>pat1: <code>[['A', 'B']]  # NOTE: [['B', 'A']] is same in my problem</code></li>
  </ul>