def group_by(seq, f):
  """ A proper groupby that doesn't require sorted input. Output is a dict,
      rather than an interator
      >>> group_by([1,2,3,4,5], mod_two)
      {0: [2, 4], 1: [1, 3, 4]}
  """
  ret = {}
  [ret.setdefault(f(i), []).append(i) for i in seq]
  return ret