cf.FieldList.sort

FieldList.sort(cmp=None, key=None, reverse=False)[source]

Sort the fields in place.

This method has exactly the same functionality as the built-in list.sort method.

The sort is stable in that if multiple fields have the same key value then their original order is preserved.

Parameters :
cmp : optional

See the built-in list.

key : optional

See the built-in list.

reverse : bool, optional

See the built-in list.

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'))

Place the fields in reverse standard name order:

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

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

>>> from operator import attrgetter
>>> 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.FieldList.reverse

Next topic

cf.AncillaryVariables

This Page