code: def unique_value_groups(ar, sort=True):
      inverse, values = pd.factorize(ar, sort=sort)
      groups = [[] for _ in range(len(values))]
      for n, g in enumerate(inverse):
          if g >= 0:
              groups[g].append(n)
      return values, groups