code: def _group_by(data, criteria):
      """
      Group objects in data using a function or a key
      """
      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
  
imports: from copy import copy
  from inspect import signature, _empty
  import re
  from collections.abc import Iterable
  from collections import defaultdict
  from itertools import product
  from six import string_types
label_desc: Use image node_id 8 for calling a global function with example usage: _group_by(data, criteria) and returns: res, x