nodes: 0, module; 1, function_definition; 2, function_name:number_aware_alphabetical_cmp; 3, parameters; 4, block; 5, identifier:str1; 6, identifier:str2; 7, expression_statement; 8, function_definition; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, while_statement; 14, if_statement; 15, return_statement; 16, comment:""" cmp function for sorting a list of strings by alphabetical order, but with
          numbers sorted numerically.
  
          i.e., foo1, foo2, foo10, foo11
          instead of foo1, foo10
      """; 17, function_name:flatten_tokens; 18, parameters; 19, block; 20, assignment; 21, assignment; 22, assignment; 23, assignment; 24, comparison_operator:i < l; 25, block; 26, comparison_operator:len(seq1) < len(seq2); 27, block; 28, elif_clause; 29, integer:0; 30, identifier:tokens; 31, expression_statement; 32, for_statement; 33, return_statement; 34, identifier:seq1; 35, call; 36, identifier:seq2; 37, call; 38, identifier:l; 39, call; 40, identifier:i; 41, integer:0; 42, identifier:i; 43, identifier:l; 44, if_statement; 45, expression_statement; 46, call; 47, call; 48, return_statement; 49, comparison_operator:len(seq1) > len(seq2); 50, block; 51, assignment; 52, identifier:token; 53, identifier:tokens; 54, block; 55, identifier:l; 56, identifier:flatten_tokens; 57, argument_list; 58, identifier:flatten_tokens; 59, argument_list; 60, identifier:min; 61, argument_list; 62, comparison_operator:seq1[i] < seq2[i]; 63, block; 64, elif_clause; 65, augmented_assignment; 66, identifier:len; 67, argument_list; 68, identifier:len; 69, argument_list; 70, unary_operator; 71, call; 72, call; 73, return_statement; 74, identifier:l; 75, list; 76, if_statement; 77, call; 78, call; 79, call; 80, call; 81, subscript; 82, subscript; 83, return_statement; 84, comparison_operator:seq1[i] > seq2[i]; 85, block; 86, identifier:i; 87, integer:1; 88, identifier:seq1; 89, identifier:seq2; 90, integer:1; 91, identifier:len; 92, argument_list; 93, identifier:len; 94, argument_list; 95, integer:1; 96, call; 97, block; 98, else_clause; 99, identifier:tokenize_by_number; 100, argument_list; 101, identifier:tokenize_by_number; 102, argument_list; 103, identifier:len; 104, argument_list; 105, identifier:len; 106, argument_list; 107, identifier:seq1; 108, identifier:i; 109, identifier:seq2; 110, identifier:i; 111, unary_operator; 112, subscript; 113, subscript; 114, return_statement; 115, identifier:seq1; 116, identifier:seq2; 117, identifier:isinstance; 118, argument_list; 119, for_statement; 120, block; 121, identifier:str1; 122, identifier:str2; 123, identifier:seq1; 124, identifier:seq2; 125, integer:1; 126, identifier:seq1; 127, identifier:i; 128, identifier:seq2; 129, identifier:i; 130, integer:1; 131, identifier:token; 132, identifier:str; 133, identifier:char; 134, identifier:token; 135, block; 136, assert_statement; 137, expression_statement; 138, expression_statement; 139, call; 140, call; 141, call; 142, identifier:isinstance; 143, argument_list; 144, attribute; 145, argument_list; 146, attribute; 147, argument_list; 148, identifier:token; 149, identifier:float; 150, identifier:l; 151, identifier:append; 152, identifier:token; 153, identifier:l; 154, identifier:append; 155, identifier:char
code: def number_aware_alphabetical_cmp(str1, str2):
      """ cmp function for sorting a list of strings by alphabetical order, but with
          numbers sorted numerically.
  
          i.e., foo1, foo2, foo10, foo11
          instead of foo1, foo10
      """
  
      def flatten_tokens(tokens):
          l = []
          for token in tokens:
              if isinstance(token, str):
                  for char in token:
                      l.append(char)
              else:
                  assert isinstance(token, float)
                  l.append(token)
          return l
  
      seq1 = flatten_tokens(tokenize_by_number(str1))
      seq2 = flatten_tokens(tokenize_by_number(str2))
  
      l = min(len(seq1),len(seq2))
  
      i = 0
  
      while i < l:
          if seq1[i] < seq2[i]:
              return -1
          elif seq1[i] > seq2[i]:
              return 1
          i += 1
  
      if len(seq1) < len(seq2):
          return -1
      elif len(seq1) > len(seq2):
          return 1
  
      return 0