title: Shuffle groups of sublists in Python
body: <p>I want to shuffle this list:</p>
  
  <pre><code>[[1, 'A'], [2, 'A'], [6, 'B'], [3, 'B'], [4, 'C'], [5, 'C'], [7, 'F']]
  </code></pre>
  
  <p>But I need groups identified by sublists second elements to stay together, so that the shuffled list could look like this: </p>
  
  <pre><code>[[6, 'B'], [3, 'B'], [7, 'F'], [1, 'A'], [2, 'A'], [4, 'C'], [5, 'C']]
  </code></pre>
  
  <p>Where all 'B', 'F', 'A', and 'C' sublists stay together.</p>
  
  <p>I'm guessing using a combination of shuffle and groupby would do the trick, but I don't know where to start with this. Any idea would be appreciated!</p>