title: PySpark map dataframe row values to distinct elements in a column
body: <p>I need to map a dataframe that looks like this:</p>
  
  
  
  <pre class="lang-none prettyprint-override"><code>+-------+-----------+
  |    key|     value |
  +-------+-----------+
  |      A| ['x', 'y']|
  |      B| ['y', 'z']|
  |      C|      ['z']|
  +-------+-----------+
  </code></pre>
  
  <p>To something like this</p>
  
  <pre class="lang-none prettyprint-override"><code>+-------+------------------------+
  |    key|                  value |
  +-------+------------------------+
  |      A|{'x': 1, 'y': 1, 'z': 0}|
  |      B|{'x': 0, 'y': 1, 'z': 1}|
  |      C|{'x': 0, 'y': 0, 'z': 1}|
  +-------+------------------------+
  </code></pre>
  
  <p>First dataframe in the column <code>value</code> contains the actual values for each key. The point is to map it against distinct elements in the whole column (value_name: 1 if exists in distinct elements else 0)</p>