nodes: 0, module; 1, function_definition; 2, function_name:find_neighbors; 3, parameters; 4, block; 5, identifier:neighbors; 6, identifier:coords; 7, identifier:I; 8, identifier:source_files; 9, identifier:f; 10, identifier:sides; 11, expression_statement; 12, for_statement; 13, return_statement; 14, comment:"""Find the tile neighbors based on filenames
  
      Parameters
      -----------
      neighbors : dict
          Dictionary that stores the neighbors. Format is
          neighbors["source_file_name"]["side"] = "neighbor_source_file_name"
      coords : list
          List of coordinates determined from the filename.
          See :py:func:`utils.parse_fn`
      I : array
          Sort index. Different sorting schemes will speed up when neighbors
          are found
      source_files : list
          List of strings of source file names
      f : callable
          Function that determines if two tiles are neighbors based on their
          coordinates. f(c1, c2) returns True if tiles are neighbors
      sides : list
          List of 2 strings that give the "side" where tiles are neighbors.
  
      Returns
      -------
      neighbors : dict
          Dictionary of neighbors
  
      Notes
      -------
      For example, if Tile1 is to the left of Tile2, then
      neighbors['Tile1']['right'] = 'Tile2'
      neighbors['Tile2']['left'] = 'Tile1'
      """; 15, pattern_list; 16, call; 17, block; 18, identifier:neighbors; 19, identifier:i; 20, identifier:c1; 21, identifier:enumerate; 22, argument_list; 23, expression_statement; 24, comment:# If the left neighbor has already been found...; 25, if_statement; 26, comment:# could try coords[i:] (+ fixes) for speed if it becomes a problem; 27, for_statement; 28, identifier:coords; 29, assignment; 30, comparison_operator:neighbors[me][sides[0]] != ''; 31, block; 32, pattern_list; 33, call; 34, block; 35, identifier:me; 36, subscript; 37, subscript; 38, string; 39, continue_statement; 40, identifier:j; 41, identifier:c2; 42, identifier:enumerate; 43, argument_list; 44, if_statement; 45, identifier:source_files; 46, subscript; 47, subscript; 48, subscript; 49, identifier:coords; 50, call; 51, comment:# then tiles are neighbors neighbors; 52, block; 53, identifier:I; 54, identifier:i; 55, identifier:neighbors; 56, identifier:me; 57, identifier:sides; 58, integer:0; 59, identifier:f; 60, argument_list; 61, expression_statement; 62, expression_statement; 63, expression_statement; 64, break_statement; 65, identifier:c1; 66, identifier:c2; 67, assignment; 68, assignment; 69, assignment; 70, identifier:neigh; 71, subscript; 72, subscript; 73, identifier:neigh; 74, subscript; 75, identifier:me; 76, identifier:source_files; 77, subscript; 78, subscript; 79, subscript; 80, subscript; 81, subscript; 82, identifier:I; 83, identifier:j; 84, identifier:neighbors; 85, identifier:me; 86, identifier:sides; 87, integer:0; 88, identifier:neighbors; 89, identifier:neigh; 90, identifier:sides; 91, integer:1
code: def find_neighbors(neighbors, coords, I, source_files, f, sides):
      """Find the tile neighbors based on filenames
  
      Parameters
      -----------
      neighbors : dict
          Dictionary that stores the neighbors. Format is
          neighbors["source_file_name"]["side"] = "neighbor_source_file_name"
      coords : list
          List of coordinates determined from the filename.
          See :py:func:`utils.parse_fn`
      I : array
          Sort index. Different sorting schemes will speed up when neighbors
          are found
      source_files : list
          List of strings of source file names
      f : callable
          Function that determines if two tiles are neighbors based on their
          coordinates. f(c1, c2) returns True if tiles are neighbors
      sides : list
          List of 2 strings that give the "side" where tiles are neighbors.
  
      Returns
      -------
      neighbors : dict
          Dictionary of neighbors
  
      Notes
      -------
      For example, if Tile1 is to the left of Tile2, then
      neighbors['Tile1']['right'] = 'Tile2'
      neighbors['Tile2']['left'] = 'Tile1'
      """
      for i, c1 in enumerate(coords):
          me = source_files[I[i]]
          # If the left neighbor has already been found...
          if neighbors[me][sides[0]] != '':
              continue
          # could try coords[i:] (+ fixes) for speed if it becomes a problem
          for j, c2 in enumerate(coords):
              if f(c1, c2):
                  # then tiles are neighbors neighbors
                  neigh = source_files[I[j]]
                  neighbors[me][sides[0]] = neigh
                  neighbors[neigh][sides[1]] = me
                  break
      return neighbors