nodes: 0, module; 1, function_definition; 2, function_name:sort_shells; 3, parameters; 4, block; 5, identifier:shells; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, comment:# Sort primitives within a shell; 10, comment:# (copying already handled above); 11, expression_statement; 12, comment:# Sort the list by increasing AM, then general contraction level, then decreasing highest exponent; 13, return_statement; 14, identifier:use_copy; 15, True; 16, comment:"""
      Sort a list of basis set shells into a standard order
  
      The order within a shell is by decreasing value of the exponent.
  
      The order of the shell list is in increasing angular momentum, and then
      by decreasing number of primitives, then decreasing value of the largest exponent.
  
      If use_copy is True, the input shells are not modified.
      """; 17, identifier:use_copy; 18, block; 19, assignment; 20, call; 21, expression_statement; 22, identifier:shells; 23, list_comprehension; 24, identifier:list; 25, argument_list; 26, assignment; 27, call; 28, for_in_clause; 29, call; 30, identifier:shells; 31, call; 32, identifier:sort_shell; 33, argument_list; 34, identifier:sh; 35, identifier:shells; 36, identifier:sorted; 37, argument_list; 38, attribute; 39, argument_list; 40, identifier:sh; 41, False; 42, identifier:shells; 43, keyword_argument; 44, identifier:copy; 45, identifier:deepcopy; 46, identifier:shells; 47, identifier:key; 48, lambda; 49, lambda_parameters; 50, tuple; 51, identifier:x; 52, call; 53, unary_operator; 54, unary_operator; 55, unary_operator; 56, identifier:max; 57, argument_list; 58, call; 59, call; 60, call; 61, subscript; 62, identifier:len; 63, argument_list; 64, identifier:len; 65, argument_list; 66, identifier:float; 67, argument_list; 68, identifier:x; 69, string; 70, subscript; 71, subscript; 72, call; 73, string_content:angular_momentum; 74, identifier:x; 75, string; 76, identifier:x; 77, string; 78, identifier:max; 79, argument_list; 80, string_content:exponents; 81, string_content:coefficients; 82, subscript; 83, identifier:x; 84, string; 85, string_content:exponents
code: def sort_shells(shells, use_copy=True):
      """
      Sort a list of basis set shells into a standard order
  
      The order within a shell is by decreasing value of the exponent.
  
      The order of the shell list is in increasing angular momentum, and then
      by decreasing number of primitives, then decreasing value of the largest exponent.
  
      If use_copy is True, the input shells are not modified.
      """
  
      if use_copy:
          shells = copy.deepcopy(shells)
  
      # Sort primitives within a shell
      # (copying already handled above)
      shells = [sort_shell(sh, False) for sh in shells]
  
      # Sort the list by increasing AM, then general contraction level, then decreasing highest exponent
      return list(
          sorted(
              shells,
              key=lambda x: (max(x['angular_momentum']), -len(x['exponents']), -len(x['coefficients']), -float(
                  max(x['exponents'])))))