title: Trouble understanding itertools.groupby() in Python
body: <p>Hello and thanks for looking at my question! I have read on the documentations for python and the top rated question for <a href="https://stackoverflow.com/questions/17156602/itertools-groupby-in-python">itertools.groupby( ) in python</a>. But I'm still confused as to how this function actually works. Can someone walk me through the <code>for rank, group in groupby (hand , lambda card: card [1])</code> iteration? Especially the <code>lambda card: card[1]</code> part. From my understanding it is just returning card[1] but there is no variable with card. Also, for <code>rank, group</code> is it because there are 2 values for each index of hand e.g. the first card is '3S' hence there is 3 and S for its values? Would there need to have a third variable if the say each index of hand were changed to 3 values? E.g. '3SH'? Sorry if this seems like a question that was already answered, I really couldn't understand it even in simple terms...</p>
  
  <pre><code>hand = ['3S', '3D', '3H', '4D']
  
  sorted_hand_by_suit = []
  for rank, group in groupby (hand , lambda card: card [1]):
      sorted_hand_by_suit.append(list(group))
  return sorted_hand_by_suit
  
  print sorted_hand_by_suit # [['3S'],['3D', '4D'], [3H]]
  </code></pre>