nodes: 0, module; 1, function_definition; 2, function_name:get_subsections; 3, parameters; 4, block; 5, identifier:srcdir; 6, identifier:examples_dir; 7, identifier:sortkey; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, return_statement; 14, comment:"""Return the list of subsections of a gallery
  
      Parameters
      ----------
      srcdir : str
          absolute path to directory containing conf.py
      examples_dir : str
          path to the examples directory relative to conf.py
      sortkey : callable
          The sort key to use.
  
      Returns
      -------
      out : list
          sorted list of gallery subsection folder names
  
      """; 15, assignment; 16, assignment; 17, assignment; 18, assignment; 19, list_comprehension; 20, identifier:subfolders; 21, list_comprehension; 22, identifier:base_examples_dir_path; 23, call; 24, identifier:subfolders_with_path; 25, list_comprehension; 26, identifier:sorted_subfolders; 27, call; 28, subscript; 29, for_in_clause; 30, identifier:subfolder; 31, for_in_clause; 32, if_clause; 33, attribute; 34, argument_list; 35, call; 36, for_in_clause; 37, identifier:sorted; 38, argument_list; 39, identifier:subfolders; 40, identifier:i; 41, identifier:i; 42, list_comprehension; 43, identifier:subfolder; 44, call; 45, call; 46, attribute; 47, identifier:relpath; 48, identifier:examples_dir; 49, identifier:srcdir; 50, attribute; 51, argument_list; 52, identifier:item; 53, identifier:subfolders; 54, identifier:subfolders_with_path; 55, keyword_argument; 56, call; 57, for_in_clause; 58, attribute; 59, argument_list; 60, attribute; 61, argument_list; 62, identifier:os; 63, identifier:path; 64, attribute; 65, identifier:join; 66, identifier:base_examples_dir_path; 67, identifier:item; 68, identifier:key; 69, identifier:sortkey; 70, attribute; 71, argument_list; 72, identifier:item; 73, identifier:sorted_subfolders; 74, identifier:os; 75, identifier:listdir; 76, identifier:examples_dir; 77, attribute; 78, identifier:exists; 79, call; 80, identifier:os; 81, identifier:path; 82, identifier:subfolders_with_path; 83, identifier:index; 84, identifier:item; 85, identifier:os; 86, identifier:path; 87, attribute; 88, argument_list; 89, attribute; 90, identifier:join; 91, identifier:examples_dir; 92, identifier:subfolder; 93, string; 94, identifier:os; 95, identifier:path; 96, string_content:README.txt
code: def get_subsections(srcdir, examples_dir, sortkey):
      """Return the list of subsections of a gallery
  
      Parameters
      ----------
      srcdir : str
          absolute path to directory containing conf.py
      examples_dir : str
          path to the examples directory relative to conf.py
      sortkey : callable
          The sort key to use.
  
      Returns
      -------
      out : list
          sorted list of gallery subsection folder names
  
      """
      subfolders = [subfolder for subfolder in os.listdir(examples_dir)
                    if os.path.exists(os.path.join(
                        examples_dir, subfolder, 'README.txt'))]
      base_examples_dir_path = os.path.relpath(examples_dir, srcdir)
      subfolders_with_path = [os.path.join(base_examples_dir_path, item)
                              for item in subfolders]
      sorted_subfolders = sorted(subfolders_with_path, key=sortkey)
  
      return [subfolders[i] for i in [subfolders_with_path.index(item)
                                      for item in sorted_subfolders]]