py::builtins::list::sort

template <class compare_func_t = std::function<reference(reference)>>
void sort(bool reverse = false, compare_func_t key = nullptr);

Removes the given element.

Template parameters

compare_func_t: The type of compare function (key).

Requirements of compare_func_t

compare_func_t must support function call operator (operator ()).

Parameters

reverse: Whether to reserve sort the list.

key: A function (can be a callable object or lambda) whose return value used as the key to sort.

Complexity

Linear in the size of the list multipled by the logarithm of the size of the list, plus linear in the size of the list if reverse sorted.

Example

#include <pypp/builtins/list.hpp>
#include <pypp/builtins/print.hpp>

int main()
{
    py::list<int> list = {0, 1, 3, 0};

    list.sort();

    py::print(list);

    list.sort(true); // Reverse

    py::print(list);
}

Output:

{0, 0, 1, 3}
{3, 1, 0, 0}