import itertools


def flock(predicate, iterable):
  """Groups elements into subsequences after sorting::

      things = [("phone", "android"),
                ("phone", "iphone"),
                ("tablet", "ipad"),
                ("laptop", "dell studio"),
                ("phone", "nokia"),
                ("laptop", "macbook pro")]

      list(flock(lambda w: w[0], things))
      -> [(("laptop", "dell studio"), ("laptop", "macbook pro")),
          (("phone", "android"), ("phone", "iphone"), ("phone", "nokia")),
          (("tablet", "ipad"),)]

      list(flock(lambda w: w[0], "mississippi"))
      -> [("i", "i", "i", "i"), ("m",), ("p", "p"), ("s", "s", "s", "s")]

  :param predicate:
      Predicate function that returns ``True`` or ``False`` for each
      element of the iterable.
  :param iterable:
      An iterable sequence of elements.
  :returns:
      An iterator of lists.
  """
  return (tuple(group) for key, group in
          itertools.groupby(sorted(iterable), predicate))