code: def map_feature_names(feature_names, max_size=63):
      """Map feature names to legal Matlab field names
  
      returns a dictionary where the key is the field name and
      the value is the feature name.
      """
      mapping = {}
      seeded = False
  
      # def shortest_first(a, b):
      #     return (
      #         -1
      #         if len(a) < len(b)
      #         else 1
      #         if len(b) < len(a)
      #         else cellprofiler_core.utilities.legacy.cmp(a, b)
      #     )
  
      for feature_name in feature_names:
          # if len(feature_name) > max_size:
          #     name = feature_name
          #     to_remove = len(feature_name) - max_size
          #     remove_count = 0
          #     for to_drop in (
          #         ("a", "e", "i", "o", "u"),
          #         (
          #             "b",
          #             "c",
          #             "d",
          #             "f",
          #             "g",
          #             "h",
          #             "j",
          #             "k",
          #             "l",
          #             "m",
          #             "n",
          #             "p",
          #             "q",
          #             "r",
          #             "s",
          #             "t",
          #             "v",
          #             "w",
          #             "x",
          #             "y",
          #             "z",
          #         ),
          #         (
          #             "A",
          #             "B",
          #             "C",
          #             "D",
          #             "E",
          #             "F",
          #             "G",
          #             "H",
          #             "I",
          #             "J",
          #             "K",
          #             "L",
          #             "M",
          #             "N",
          #             "O",
          #             "P",
          #             "Q",
          #             "R",
          #             "S",
          #             "T",
          #             "U",
          #             "V",
          #             "W",
          #             "X",
          #             "Y",
          #             "Z",
          #         ),
          #     ):
          #         for index in range(len(name) - 1, -1, -1):
          #             if name[index] in to_drop:
          #                 name = name[:index] + name[index + 1 :]
          #                 remove_count += 1
          #                 if remove_count == to_remove:
          #                     break
          #         if remove_count == to_remove:
          #             break
          #     if name in list(mapping.keys()) or len(name) > max_size:
          #         # Panic mode - a duplication
          #         if not seeded:
          #             numpy.random.seed(0)
          #             seeded = True
          #         while True:
          #             npname = numpy.fromstring(feature_name, "|S1")
          #             indices = numpy.random.permutation(len(name))[:max_size]
          #             indices.sort()
          #             name = npname[indices]
          #             name = name.tostring()
          #             if not name in list(mapping.keys()):
          #                 break
          # else:
          #     name = feature_name
          mapping[feature_name] = feature_name
      return mapping
  
imports: import bisect
  import re
  import numpy
  from ...constants.pipeline import make_cell_struct_dtype
  from ...constants.pipeline import PIPELINE
  from ...constants.pipeline import IMAGE_PLANE_DESCRIPTOR_VERSION
  from ...constants.pipeline import H_PLANE_COUNT
  from ...constants.pipeline import H_URL
  from ...constants.pipeline import H_SERIES
  from ...constants.pipeline import H_INDEX
  from ...constants.pipeline import H_CHANNEL
  from ...constants.pipeline import RF_STATE_PREQUOTE
  from ...constants.pipeline import RF_STATE_FIELD
  from ...constants.pipeline import RF_STATE_BACKSLASH_ESCAPE
  from ...constants.pipeline import RF_STATE_SEPARATOR
  from ..legacy import cmp
label_desc: Use image node_id 2 for calling a global function with example usage: map_feature_names(feature_names, max_size) and returns: mapping