title: Creating sublists from a list based on another list in python
body: <p>I have two lists: l1 and l2, which are shown below.</p>
  
  <pre><code>l1 = [0, 1, 1, 0, 1]
  l2 = [0, 0, 1, 1, 0]
  </code></pre>
  
  <p>I want to sublist l1 into a list of lists based on values in l2, like below, one for '0' and one for '1'</p>
  
  <pre><code>[[0, 1, 1], [1, 0]]
  </code></pre>
  
  <p>this basically says, for 0 in l2, there are three values in l1 and for 1 in l2, there are two values in l1.</p>
  
  <p>Is there a simple python way to do this?</p>
  
  <p>EDIT: Here is what I have done to solve. This works well, but seems clunky and strange looking. I am looking for a more elegant solution.</p>
  
  <pre><code>d = [[],[]]
  for i in range(len(l2)):
      d[l2[i]].append(l1[i])
  </code></pre>