nodes: 0, module; 1, function_definition; 2, function_name:_finish_filter; 3, parameters; 4, block; 5, identifier:self; 6, identifier:lst; 7, identifier:key; 8, identifier:include_self; 9, identifier:exclusive; 10, identifier:biggest_first; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, expression_statement; 17, comment:# RoW in both key and lst, but not defined; only RoW remains if exclusive; 18, if_statement; 19, comment:# If RoW not resolved, make it the smallest; 20, if_statement; 21, return_statement; 22, comment:"""Finish filtering a GIS operation. Can optionally exclude the input key, sort results, and exclude overlapping results. Internal function, not normally called directly."""; 23, assignment; 24, assignment; 25, boolean_operator; 26, block; 27, call; 28, assignment; 29, boolean_operator; 30, block; 31, elif_clause; 32, boolean_operator; 33, block; 34, identifier:lst; 35, identifier:key; 36, call; 37, identifier:locations; 38, list_comprehension; 39, not_operator; 40, comparison_operator:key in locations; 41, expression_statement; 42, attribute; 43, argument_list; 44, identifier:lst; 45, list_comprehension; 46, boolean_operator; 47, identifier:exclusive; 48, return_statement; 49, identifier:exclusive; 50, block; 51, comparison_operator:'RoW' not in self; 52, comparison_operator:'RoW' in lst; 53, expression_statement; 54, attribute; 55, argument_list; 56, subscript; 57, for_in_clause; 58, identifier:include_self; 59, identifier:key; 60, identifier:locations; 61, call; 62, identifier:lst; 63, identifier:sort; 64, keyword_argument; 65, keyword_argument; 66, identifier:x; 67, for_in_clause; 68, comparison_operator:key == 'RoW'; 69, comparison_operator:'RoW' not in self; 70, conditional_expression:['RoW'] if 'RoW' in lst else []; 71, expression_statement; 72, while_statement; 73, expression_statement; 74, string; 75, identifier:self; 76, string; 77, identifier:lst; 78, assignment; 79, identifier:self; 80, identifier:_actual_key; 81, identifier:key; 82, identifier:x; 83, integer:0; 84, identifier:x; 85, identifier:lst; 86, attribute; 87, argument_list; 88, identifier:key; 89, lambda; 90, identifier:reverse; 91, identifier:biggest_first; 92, pattern_list; 93, identifier:lst; 94, identifier:key; 95, string; 96, string; 97, identifier:self; 98, list; 99, comparison_operator:'RoW' in lst; 100, list; 101, assignment; 102, identifier:lst; 103, block; 104, assignment; 105, string_content:RoW; 106, string_content:RoW; 107, subscript; 108, call; 109, identifier:lst; 110, identifier:pop; 111, call; 112, lambda_parameters; 113, subscript; 114, identifier:x; 115, identifier:y; 116, string_content:RoW; 117, string_content:RoW; 118, string; 119, string; 120, identifier:lst; 121, pattern_list; 122, expression_list; 123, expression_statement; 124, expression_statement; 125, if_statement; 126, identifier:lst; 127, identifier:remaining; 128, identifier:lst; 129, conditional_expression:-1 if biggest_first else 0; 130, attribute; 131, argument_list; 132, attribute; 133, argument_list; 134, identifier:x; 135, identifier:x; 136, integer:1; 137, string_content:RoW; 138, string_content:RoW; 139, identifier:removed; 140, identifier:remaining; 141, call; 142, list; 143, assignment; 144, assignment; 145, not_operator; 146, block; 147, unary_operator; 148, identifier:biggest_first; 149, integer:0; 150, identifier:lst; 151, identifier:pop; 152, call; 153, identifier:locations; 154, identifier:index; 155, identifier:key; 156, identifier:set; 157, argument_list; 158, identifier:current; 159, call; 160, identifier:faces; 161, subscript; 162, call; 163, expression_statement; 164, expression_statement; 165, integer:1; 166, attribute; 167, argument_list; 168, attribute; 169, argument_list; 170, identifier:self; 171, identifier:current; 172, attribute; 173, argument_list; 174, call; 175, call; 176, identifier:lst; 177, identifier:index; 178, string; 179, identifier:lst; 180, identifier:pop; 181, integer:0; 182, identifier:faces; 183, identifier:intersection; 184, identifier:removed; 185, attribute; 186, argument_list; 187, attribute; 188, argument_list; 189, string_content:RoW; 190, identifier:removed; 191, identifier:update; 192, identifier:faces; 193, identifier:remaining; 194, identifier:append; 195, identifier:current
code: def _finish_filter(self, lst, key, include_self, exclusive, biggest_first):
          """Finish filtering a GIS operation. Can optionally exclude the input key, sort results, and exclude overlapping results. Internal function, not normally called directly."""
          key = self._actual_key(key)
          locations = [x[0] for x in lst]
  
          if not include_self and key in locations:
              lst.pop(locations.index(key))
  
          lst.sort(key=lambda x: x[1], reverse=biggest_first)
          lst = [x for x, y in lst]
  
          # RoW in both key and lst, but not defined; only RoW remains if exclusive
          if key == 'RoW' and 'RoW' not in self and exclusive:
              return ['RoW'] if 'RoW' in lst else []
          elif exclusive:
              removed, remaining = set(), []
              while lst:
                  current = lst.pop(0)
                  faces = self[current]
                  if not faces.intersection(removed):
                      removed.update(faces)
                      remaining.append(current)
              lst = remaining
  
          # If RoW not resolved, make it the smallest
          if 'RoW' not in self and 'RoW' in lst:
              lst[-1 if biggest_first else 0] = lst.pop(lst.index('RoW'))
  
          return lst