title: Python list of dict into a 2D list
body: <p><strong>Input</strong></p>
  <p>Couldn't get my head round this: I've got a python list of dictionaries like so:</p>
  <pre class="lang-py prettyprint-override"><code>d = [{'a': ['a1', 'a2', 'a3'], 'b': ['b1', 'b2']}, {...}, {...}]
  </code></pre>
  <p>Important notes:</p>
  <ul>
  <li>number of keys ('a', 'b' ...) is const (e.g. from A to Z)</li>
  <li>lengths of values (lists) is arbitrary, it may even be an empty list</li>
  <li>elements in values don't matter and are here shown as 'a1', 'b2' for clarity only</li>
  </ul>
  <p><strong>Expected result</strong></p>
  <p>I need to flatten the nested lists into a 2D list of separate dicts like so:</p>
  <pre class="lang-py prettyprint-override"><code>d = [ 
          [ {'key': 'a', 'val': 'a1'}, {'key': 'b', 'val': 'b1'}, {...} ],
          [ {'key': 'a', 'val': 'a2'}, {'key': 'b', 'val': 'b2'}, {...} ],
          [ {'key': 'a', 'val': 'a3'}, {'key': 'b', 'val': 'b3'}, {...} ],
          [ ... ]
      ]
  </code></pre>
  <p>That is, each dict is atomic containing to items: 'key' that stands for the original keys, and 'val' - the original lists broken element wise. Since the number of keys is const, the inner lists must have equal lengths. So this is basically a permutation problem.</p>
  <p><strong>Note</strong>
  Since the number is elements in the values (lists) is not const, the permutations must be able to pad the shorter lists with None or use the end elements. For example:</p>
  <pre class="lang-py prettyprint-override"><code>[
    [ {'key': 'a', 'val': 'a5'}, # -- last possible value for 'a' =5
      {'key': 'b', 'val': 'b100'}, # -- but 'b' has at least 100 values...
      ...
    ],
    [ {'key': 'a', 'val': 'a5'}, # -- ...so the next list uses the same val for 'a'
      {'key': 'b', 'val': 'b101'}, # -- ...and a next one for 'b'
      ...
    ],
  ]
  </code></pre>
  <p>Tried <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_dict.html" rel="nofollow noreferrer">pandas.to_dict</a> and various native python tricks, but just couldn't succeed... For example, <code>pandas.to_dict('list')</code> gives</p>
  <pre><code>{ 'keys': ['a', 'b', ...], 'vals': [[a1, a2, ...], ['b1', 'b2', ...]]}
  </code></pre>