nodes: 0, module; 1, function_definition; 2, function_name:filenames; 3, parameters; 4, block; 5, identifier:directory; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, if_statement; 12, return_statement; 13, identifier:tag; 14, string; 15, identifier:sorted; 16, False; 17, identifier:recursive; 18, False; 19, comment:""" Reads in all filenames from a directory that contain a specified substring.
  
      Parameters
      ----------
      directory : :obj:`str`
          the directory to read from
      tag : :obj:`str`
          optional tag to match in the filenames
      sorted : bool
          whether or not to sort the filenames
      recursive : bool
          whether or not to search for the files recursively
  
      Returns
      -------
      :obj:`list` of :obj:`str`
          filenames to read from
      """; 20, identifier:recursive; 21, block; 22, else_clause; 23, identifier:sorted; 24, block; 25, identifier:f; 26, expression_statement; 27, block; 28, expression_statement; 29, assignment; 30, expression_statement; 31, call; 32, identifier:f; 33, list_comprehension; 34, assignment; 35, attribute; 36, argument_list; 37, call; 38, for_in_clause; 39, for_in_clause; 40, if_clause; 41, identifier:f; 42, list_comprehension; 43, identifier:f; 44, identifier:sort; 45, attribute; 46, argument_list; 47, pattern_list; 48, call; 49, identifier:f; 50, identifier:filename; 51, comparison_operator:f.find(tag) > -1; 52, call; 53, for_in_clause; 54, if_clause; 55, attribute; 56, identifier:join; 57, identifier:directory; 58, identifier:f; 59, identifier:directory; 60, identifier:_; 61, identifier:filename; 62, attribute; 63, argument_list; 64, call; 65, unary_operator; 66, attribute; 67, argument_list; 68, identifier:f; 69, call; 70, comparison_operator:f.find(tag) > -1; 71, identifier:os; 72, identifier:path; 73, identifier:os; 74, identifier:walk; 75, identifier:directory; 76, attribute; 77, argument_list; 78, integer:1; 79, attribute; 80, identifier:join; 81, identifier:directory; 82, identifier:f; 83, attribute; 84, argument_list; 85, call; 86, unary_operator; 87, identifier:f; 88, identifier:find; 89, identifier:tag; 90, identifier:os; 91, identifier:path; 92, identifier:os; 93, identifier:listdir; 94, identifier:directory; 95, attribute; 96, argument_list; 97, integer:1; 98, identifier:f; 99, identifier:find; 100, identifier:tag
code: def filenames(directory, tag='', sorted=False, recursive=False):
      """ Reads in all filenames from a directory that contain a specified substring.
  
      Parameters
      ----------
      directory : :obj:`str`
          the directory to read from
      tag : :obj:`str`
          optional tag to match in the filenames
      sorted : bool
          whether or not to sort the filenames
      recursive : bool
          whether or not to search for the files recursively
  
      Returns
      -------
      :obj:`list` of :obj:`str`
          filenames to read from
      """
      if recursive:
          f = [os.path.join(directory, f) for directory, _, filename in os.walk(directory) for f in filename if f.find(tag) > -1] 
      else:
          f = [os.path.join(directory, f) for f in os.listdir(directory) if f.find(tag) > -1]
      if sorted:
          f.sort()
      return f