code: def invert_dict(d):
      
      # Based on recipe from ASPN
      result = {}
      for k, v in d.items():
          keys = result.setdefault(v, [])
          keys.append(k)
      return result
docs: Invert a dictionary with keys matching each value turned into a list.