code: def make_compact(creation_sequence):
      """
      Returns the creation sequence in a compact form
      that is the number of 'i's and 'd's alternating.
  
      Examples
      --------
      >>> from networkx.algorithms.threshold import make_compact
      >>> make_compact(["d", "i", "i", "d", "d", "i", "i", "i"])
      [1, 2, 2, 3]
      >>> make_compact(["d", "d", "d", "i", "d", "d"])
      [3, 1, 2]
  
      Notice that the first number is the first vertex
      to be used for construction and so is always 'd'.
  
      Labeled creation sequences lose their labels in the
      compact representation.
  
      >>> make_compact([3, 1, 2])
      [3, 1, 2]
      """
      first = creation_sequence[0]
      if isinstance(first, str):  # creation sequence
          cs = creation_sequence[:]
      elif isinstance(first, tuple):  # labeled creation sequence
          cs = [s[1] for s in creation_sequence]
      elif isinstance(first, int):  # compact creation sequence
          return creation_sequence
      else:
          raise TypeError("Not a valid creation sequence type")
  
      ccs = []
      count = 1  # count the run lengths of d's or i's.
      for i in range(1, len(cs)):
          if cs[i] == cs[i - 1]:
              count += 1
          else:
              ccs.append(count)
              count = 1
      ccs.append(count)  # don't forget the last one
      return ccs
  
imports: from math import sqrt
  import networkx
  from networkx.utils import py_random_state
label_desc: Use image node_id 4 for calling a global function with example usage: make_compact(creation_sequence) and returns: ccs, creation_sequence