code: def completions_sorting_key(word):
      """key for sorting completions
  
      This does several things:
  
      - Lowercase all completions, so they are sorted alphabetically with
        upper and lower case words mingled
      - Demote any completions starting with underscores to the end
      - Insert any %magic and %%cellmagic completions in the alphabetical order
        by their name
      """
      # Case insensitive sort
      word = word.lower()
  
      prio1, prio2 = 0, 0
  
      if word.startswith("__"):
          prio1 = 2
      elif word.startswith("_"):
          prio1 = 1
  
      if word.endswith("="):
          prio1 = -1
  
      if word.startswith("%%"):
          # If there's another % in there, this is something else, so leave it alone
          if not "%" in word[2:]:
              word = word[2:]
              prio2 = 2
      elif word.startswith("%"):
          if not "%" in word[1:]:
              word = word[1:]
              prio2 = 1
  
      return prio1, word, prio2
  
imports: from __future__ import print_function
  import __main__
  import glob
  import inspect
  import itertools
  import keyword
  import os
  import re
  import sys
  import unicodedata
  import string
  import warnings
  from traitlets.config.configurable import Configurable
  from IPython.core.error import TryNext
  from IPython.core.inputsplitter import ESC_MAGIC
  from IPython.core.latex_symbols import latex_symbols, reverse_latex_symbol
  from IPython.utils import generics
  from IPython.utils.decorators import undoc
  from IPython.utils.dir2 import dir2, get_real_method
  from IPython.utils.process import arg_split
  from IPython.utils.py3compat import builtin_mod, string_types, PY3, cast_unicode_py2
  from traitlets import Bool, Enum, observe
label_desc: Use image node_id 5 for calling a global function with example usage: completions_sorting_key(word) and returns: prio1,  word,  prio2