title: Apache Beam - how to split a PCollection into 2 by key in Python
body: <p>Suppose we have 2 PCollections:</p>
  
  <p>PCollection 1:</p>
  
  <pre><code>[&lt;ID_1, some_data&gt;, &lt;ID_2, some_data&gt;, ... &lt;ID_5, some_data&gt;]
  </code></pre>
  
  <p>PCollection 2:</p>
  
  <pre><code>[&lt;ID_2&gt;, &lt;ID_5&gt;]
  </code></pre>
  
  <p>Both PCollections are bounded, but can be huge (so prefer no side input).</p>
  
  <p>Say we want to split PCollection1 into 2, decided by whether the ID_x exists in PCollection 2, i.e. one PCollection will have 
  <code>[&lt;ID_1, some_data&gt;, &lt;ID_3, some_data&gt;, &lt;ID_4, some_data&gt;]</code> and another <code>[&lt;ID_2, some_data&gt;, &lt;ID_5, some_data&gt;]</code>. How to achieve this?</p>
  
  <p>It seems that <code>Partition</code> transform is the way to go but I cannot figure out how.</p>
  
  <p>But the way, I am using Python.</p>