code: def filtered(self, feature_filter, x=None):
          # type: (Callable, Any) -> Tuple[FeatureNames, List[int]]
          
          indices = []
          filtered_feature_names = []
          indexed_names = None  # type: Optional[Iterable[Tuple[int, Any]]]
          if isinstance(self.feature_names, (np.ndarray, list)):
              indexed_names = enumerate(self.feature_names)
          elif isinstance(self.feature_names, dict):
              indexed_names = six.iteritems(self.feature_names)
          elif self.feature_names is None:
              indexed_names = []
          assert indexed_names is not None
  
          if x is not None:
              if sp.issparse(x) and len(x.shape) == 2:
                  assert x.shape[0] == 1
                  flt = lambda nm, i: feature_filter(nm, x[0, i])
              else:
                  # FIXME: mypy warns about x[i] because it thinks x can be None
                  flt = lambda nm, i: feature_filter(nm, x[i])  # type: ignore
          else:
              flt = lambda nm, i: feature_filter(nm)
  
          for idx, name in indexed_names:
              if any(flt(nm, idx) for nm in _all_feature_names(name)):
                  indices.append(idx)
                  filtered_feature_names.append(name)
          if self.has_bias and flt(self.bias_name, self.bias_idx):
              assert self.bias_idx is not None  # for mypy
              bias_name = self.bias_name
              indices.append(self.bias_idx)
          else:
              bias_name = None
          return (
              FeatureNames(
                  filtered_feature_names,
                  bias_name=bias_name,
                  unkn_template=self.unkn_template,
              ),
              indices)
docs: Return feature names filtered by a regular expression 
          ``feature_re``, and indices of filtered elements.