nodes: 0, module; 1, function_definition; 2, function_name:natsort_key; 3, parameters; 4, block; 5, identifier:val; 6, identifier:key; 7, identifier:string_func; 8, identifier:bytes_func; 9, identifier:num_func; 10, expression_statement; 11, comment:# Apply key if needed; 12, if_statement; 13, comment:# Assume the input are strings, which is the most common case; 14, try_statement; 15, comment:"""
      Key to sort strings and numbers naturally.
  
      It works by splitting the string into components of strings and numbers,
      and then converting the numbers into actual ints or floats.
  
      Parameters
      ----------
      val : str | unicode | bytes | int | float | iterable
      key : callable | None
          A key to apply to the *val* before any other operations are performed.
      string_func : callable
          If *val* (or the output of *key* if given) is of type *str*, this
          function will be applied to it. The function must return
          a tuple.
      bytes_func : callable
          If *val* (or the output of *key* if given) is of type *bytes*, this
          function will be applied to it. The function must return
          a tuple.
      num_func : callable
          If *val* (or the output of *key* if given) is not of type *bytes*,
          *str*, nor is iterable, this function will be applied to it.
          The function must return a tuple.
  
      Returns
      -------
      out : tuple
          The string split into its string and numeric components.
          It *always* starts with a string, and then alternates
          between numbers and strings (unless it was applied
          recursively, in which case it will return tuples of tuples,
          but the lowest-level tuples will then *always* start with
          a string etc.).
  
      See Also
      --------
      parse_string_factory
      parse_bytes_factory
      parse_number_factory
  
      """; 16, comparison_operator:key is not None; 17, block; 18, block; 19, except_clause; 20, identifier:key; 21, None; 22, expression_statement; 23, return_statement; 24, tuple; 25, comment:# If bytes type, use the bytes_func; 26, block; 27, assignment; 28, call; 29, identifier:TypeError; 30, identifier:AttributeError; 31, if_statement; 32, comment:# Otherwise, assume it is an iterable that must be parsed recursively.; 33, comment:# Do not apply the key recursively.; 34, try_statement; 35, identifier:val; 36, call; 37, identifier:string_func; 38, argument_list; 39, comparison_operator:type(val) in (bytes,); 40, block; 41, block; 42, comment:# If that failed, it must be a number.; 43, except_clause; 44, identifier:key; 45, argument_list; 46, identifier:val; 47, call; 48, tuple; 49, return_statement; 50, return_statement; 51, identifier:TypeError; 52, block; 53, identifier:val; 54, identifier:type; 55, argument_list; 56, identifier:bytes; 57, call; 58, call; 59, return_statement; 60, identifier:val; 61, identifier:bytes_func; 62, argument_list; 63, identifier:tuple; 64, generator_expression; 65, call; 66, identifier:val; 67, call; 68, for_in_clause; 69, identifier:num_func; 70, argument_list; 71, identifier:natsort_key; 72, argument_list; 73, identifier:x; 74, identifier:val; 75, identifier:val; 76, identifier:x; 77, None; 78, identifier:string_func; 79, identifier:bytes_func; 80, identifier:num_func
code: def natsort_key(val, key, string_func, bytes_func, num_func):
      """
      Key to sort strings and numbers naturally.
  
      It works by splitting the string into components of strings and numbers,
      and then converting the numbers into actual ints or floats.
  
      Parameters
      ----------
      val : str | unicode | bytes | int | float | iterable
      key : callable | None
          A key to apply to the *val* before any other operations are performed.
      string_func : callable
          If *val* (or the output of *key* if given) is of type *str*, this
          function will be applied to it. The function must return
          a tuple.
      bytes_func : callable
          If *val* (or the output of *key* if given) is of type *bytes*, this
          function will be applied to it. The function must return
          a tuple.
      num_func : callable
          If *val* (or the output of *key* if given) is not of type *bytes*,
          *str*, nor is iterable, this function will be applied to it.
          The function must return a tuple.
  
      Returns
      -------
      out : tuple
          The string split into its string and numeric components.
          It *always* starts with a string, and then alternates
          between numbers and strings (unless it was applied
          recursively, in which case it will return tuples of tuples,
          but the lowest-level tuples will then *always* start with
          a string etc.).
  
      See Also
      --------
      parse_string_factory
      parse_bytes_factory
      parse_number_factory
  
      """
  
      # Apply key if needed
      if key is not None:
          val = key(val)
  
      # Assume the input are strings, which is the most common case
      try:
          return string_func(val)
      except (TypeError, AttributeError):
  
          # If bytes type, use the bytes_func
          if type(val) in (bytes,):
              return bytes_func(val)
  
          # Otherwise, assume it is an iterable that must be parsed recursively.
          # Do not apply the key recursively.
          try:
              return tuple(
                  natsort_key(x, None, string_func, bytes_func, num_func) for x in val
              )
  
          # If that failed, it must be a number.
          except TypeError:
              return num_func(val)