import random


def pick_max(distribution):
  """Pick the value with the max weight from a list of (element, weight) pairs."""
  distribution = list(distribution)  # Reify potential generator
  max_w = max(w for x, w in distribution)
  opts = [x for x, w in distribution if w == max_w]
  return random.choice(opts)