code: def sort_magic_data(magic_data, sort_name):
      '''
      Sort magic_data by header (like er_specimen_name for example)
      '''
      magic_data_sorted = {}
      for rec in magic_data:
          name = rec[sort_name]
          if name not in list(magic_data_sorted.keys()):
              magic_data_sorted[name] = []
          magic_data_sorted[name].append(rec)
      return magic_data_sortef sort_magic_data(magic_data, sort_name):
      '''
      Sort magic_data by header (like er_specimen_name for example)
      '''
      magic_data_sorted = {}
      for rec in magic_data:
          name = rec[sort_name]
          if name not in list(magic_data_sorted.keys()):
              magic_data_sorted[name] = []
          magic_data_sorted[name].append(rec)
      return magic_data_sorted
docs: Sort magic_data by header (like er_specimen_name for example)