nodes: 0, module; 1, function_definition; 2, function_name:list_files; 3, parameters; 4, block; 5, identifier:d; 6, default_parameter; 7, expression_statement; 8, if_statement; 9, if_statement; 10, return_statement; 11, identifier:extension; 12, None; 13, string; 14, call; 15, block; 16, else_clause; 17, comparison_operator:extension is not None; 18, block; 19, identifier:files; 20, string_content:Lists files in a given directory.
  
      Args:
  
          d (str): Path to a directory.
  
          extension (str): If supplied, only files that contain the
              specificied extension will be returned. Default is ``False``,
              which returns all files in ``d``.
  
      Returns:
  
          list: A sorted list of file paths.; 21, attribute; 22, argument_list; 23, expression_statement; 24, expression_statement; 25, block; 26, identifier:extension; 27, None; 28, if_statement; 29, expression_statement; 30, attribute; 31, identifier:isdir; 32, identifier:d; 33, assignment; 34, assignment; 35, expression_statement; 36, comparison_operator:type(extension) in STR_TYPES; 37, block; 38, assignment; 39, identifier:os; 40, identifier:path; 41, identifier:expanded_dir; 42, call; 43, identifier:files; 44, call; 45, assignment; 46, call; 47, identifier:STR_TYPES; 48, expression_statement; 49, identifier:files; 50, list_comprehension; 51, attribute; 52, argument_list; 53, identifier:sorted; 54, argument_list; 55, identifier:files; 56, list; 57, identifier:type; 58, argument_list; 59, assignment; 60, identifier:f; 61, for_in_clause; 62, if_clause; 63, attribute; 64, identifier:expanduser; 65, identifier:d; 66, call; 67, identifier:d; 68, identifier:extension; 69, identifier:extension; 70, list; 71, identifier:f; 72, identifier:files; 73, call; 74, identifier:os; 75, identifier:path; 76, attribute; 77, argument_list; 78, identifier:extension; 79, identifier:any; 80, argument_list; 81, identifier:glob; 82, identifier:glob; 83, binary_operator:expanded_dir + '/*'; 84, list; 85, identifier:expanded_dir; 86, string; 87, comparison_operator:f.split('.')[-1] in extension; 88, comparison_operator:f.split('.')[-1].upper() in extension; 89, comparison_operator:f.split('.')[-1].lower() in extension; 90, string_content:/*; 91, subscript; 92, identifier:extension; 93, call; 94, identifier:extension; 95, call; 96, identifier:extension; 97, call; 98, unary_operator; 99, attribute; 100, argument_list; 101, attribute; 102, argument_list; 103, attribute; 104, argument_list; 105, integer:1; 106, subscript; 107, identifier:upper; 108, subscript; 109, identifier:lower; 110, identifier:f; 111, identifier:split; 112, string; 113, call; 114, unary_operator; 115, call; 116, unary_operator; 117, string_content:.; 118, attribute; 119, argument_list; 120, integer:1; 121, attribute; 122, argument_list; 123, integer:1; 124, identifier:f; 125, identifier:split; 126, string; 127, identifier:f; 128, identifier:split; 129, string; 130, string_content:.; 131, string_content:.
code: def list_files(d, extension=None):
      '''
      Lists files in a given directory.
  
      Args:
  
          d (str): Path to a directory.
  
          extension (str): If supplied, only files that contain the
              specificied extension will be returned. Default is ``False``,
              which returns all files in ``d``.
  
      Returns:
  
          list: A sorted list of file paths.
      '''
      if os.path.isdir(d):
          expanded_dir = os.path.expanduser(d)
          files = sorted(glob.glob(expanded_dir + '/*'))
      else:
          files = [d, ]
      if extension is not None:
          if type(extension) in STR_TYPES:
              extension = [extension, ]
          files = [f for f in files if any([f.split('.')[-1] in extension,
                                            f.split('.')[-1].upper() in extension,
                                            f.split('.')[-1].lower() in extension])]
      return files