title: Can I group / aggregate elements in a list (or dict) comprehension?
body: <p>I have a list of tuples, as shown below:</p>
  
  <pre><code>[
      (1, "red")
      (1, "red,green")
      (1, "green,blue")
      (2, "green")
      (2, "yellow,blue")
  ]
  </code></pre>
  
  <p>I am trying to roll up the data, so that I can get the following dict output:</p>
  
  <pre><code>{
      1: ["red", "green", "blue"]
      2: ["green", "yellow", "blue"]
  }
  </code></pre>
  
  <p>Notes are: the strings of colours are combined for the primary key (the number), and then split into a list, and de-duped (e.g. using <code>set</code>).</p>
  
  <p>I'd also like to do the inverse, and group by the colours:</p>
  
  <pre><code>{
      "red": [1],
      "green": [1, 2]
      "yellow": [2]
      "blue": [1, 2]
  }
  </code></pre>
  
  <p>I can clearly do this by looping through all of the tuples, but I'd like to try and do it with list / dict comprehensions if possible.</p>