code: def _group_by(data, criteria):
      
      if isinstance(criteria, str):
          criteria_str = criteria
  
          def criteria(x):
              return x[criteria_str]
  
      res = defaultdict(list)
      for element in data:
          key = criteria(element)
          res[key].append(element)
      return res
docs: Group objects in data using a function or a key