cf.VariableList.sort

VariableList.sort(*args, **kwargs)[source]

Sort the elements in place.

The sort is stable which means that when multiple records have the same key, their original order is preserved.

Parameters :
args, kwargs :

As for the built-in list’s sort method.

Returns :

None

Examples

Two ways of sorting by standard name:

>>> fl.sort(key=lambda f: f.standard_name)
>>> from operator import attrgetter
>>> fl.sort(key=attrgetter('standard_name'))

Get the elements in reverse standard name order:

>>> fl.sort(key=attrgetter('standard_name'), reverse=True)

Sort by standard name then by the value of the first element of the data array:

>>> fl.sort(key=attrgetter('standard_name', 'first_datum'))

Sort by standard name then by the value of the second element of the data array:

>>> fl.sort(key=lambda f: (f.standard_name, f.subspace[..., 1].first_datum))

Previous topic

cf.VariableList.setprop

Next topic

cf.VariableList.subspace

This Page