Repository: scikit-learn/scikit-learn
File: sklearn/base.py (Python)

Code before:
                and is_scalar_nan(param_value)
            ):
                return True

            return False

        # reorder the parameters from `self.get_params` using the `__init__`
        # signature
        remaining_params = [name for name in out if name not in init_default_params]
        ordered_dict = {name: out[name] for name in init_default_params if name in out}
        ordered_dict.update({name: out[name] for name in remaining_params})

        non_default_ls = tuple(
            [
                name
                for name, value in ordered_dict.items()
                if is_non_default(name, value)
            ]
        )

        output_dict = {
            name: out[name] for name in ordered_dict if name in non_default_ls
        }
        output_dict.update(
            {name: out[name] for name in ordered_dict if name not in non_default_ls}
        )

        return ParamsDict(
            params=output_dict,
            non_default=non_default_ls,
            estimator_class=self.__class__,
            doc_link=doc_link,
        )

    def set_params(self, **params):
        """Set the parameters of this estimator.

        The method works on simple estimators as well as on nested objects
        (such as :class:`~sklearn.pipeline.Pipeline`). The latter have
        parameters of the form ``<component>__<parameter>`` so that it's
        possible to update each component of a nested object.

        Parameters
        ----------
        **params : dict
            Estimator parameters.

        Returns
        -------
        self : estimator instance
            Estimator instance.

Review comment (suggestion):
```suggestion
            name for name in ordered_params if is_non_default(name, out[name])
        )

        non_default_set = set(non_default_ls)  # For O(1) lookup
        ordered_params.sort(key=lambda name: name not in non_default_set)
        output_dict = {name: out[name] for name in ordered_params}
```

Code after:
                and is_scalar_nan(param_value)
            ):
                return True

            return False

        # Sort parameters so non-default parameters are shown first
        unordered_params = {
            name: out[name] for name in init_default_params if name in out
        }
        unordered_params.update(
            {
                name: value
                for name, value in out.items()
                if name not in init_default_params
            }
        )

        non_default_params, default_params = [], []
        for name, value in unordered_params.items():
            if is_non_default(name, value):
                non_default_params.append(name)
            else:
                default_params.append(name)

        params = {name: out[name] for name in non_default_params + default_params}

        return ParamsDict(
            params=params,
            non_default=tuple(non_default_params),
            estimator_class=self.__class__,
            doc_link=doc_link,
        )

    def set_params(self, **params):
        """Set the parameters of this estimator.

        The method works on simple estimators as well as on nested objects
        (such as :class:`~sklearn.pipeline.Pipeline`). The latter have
        parameters of the form ``<component>__<parameter>`` so that it's
        possible to update each component of a nested object.

        Parameters
        ----------
        **params : dict
            Estimator parameters.

        Returns
        -------
        self : estimator instance
            Estimator instance.