nodes: 0, module; 1, function_definition; 2, function_name:_sort_modules; 3, parameters; 4, block; 5, identifier:mods; 6, expression_statement; 7, function_definition; 8, return_statement; 9, comment:""" Always sort `index` or `README` as first filename in list. """; 10, function_name:compare; 11, parameters; 12, block; 13, call; 14, identifier:x; 15, identifier:y; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, if_statement; 20, if_statement; 21, return_statement; 22, identifier:sorted; 23, argument_list; 24, assignment; 25, assignment; 26, comparison_operator:x == y; 27, block; 28, comparison_operator:y.stem == "__init__.py"; 29, block; 30, boolean_operator; 31, block; 32, integer:1; 33, identifier:mods; 34, keyword_argument; 35, identifier:x; 36, subscript; 37, identifier:y; 38, subscript; 39, identifier:x; 40, identifier:y; 41, return_statement; 42, attribute; 43, string:"__init__.py"; 44, return_statement; 45, comparison_operator:x.stem == "__init__.py"; 46, comparison_operator:x < y; 47, return_statement; 48, identifier:key; 49, call; 50, identifier:x; 51, integer:1; 52, identifier:y; 53, integer:1; 54, integer:0; 55, identifier:y; 56, identifier:stem; 57, integer:1; 58, attribute; 59, string:"__init__.py"; 60, identifier:x; 61, identifier:y; 62, unary_operator; 63, identifier:cmp_to_key; 64, argument_list; 65, identifier:x; 66, identifier:stem; 67, integer:1; 68, identifier:compare
code: def _sort_modules(mods):
      """ Always sort `index` or `README` as first filename in list. """
  
      def compare(x, y):
          x = x[1]
          y = y[1]
          if x == y:
              return 0
          if y.stem == "__init__.py":
              return 1
          if x.stem == "__init__.py" or x < y:
              return -1
          return 1
  
      return sorted(mods, key=cmp_to_key(compare))