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 long name:

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

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.datum(1)))

Sort by reverse order of the first time coordinate value:

>>> fl.sort(key=lambda f: f.coord('T').Data[0], reverse=True)

Previous topic

cf.FieldList.reverse

Next topic

cf.AncillaryVariables

This Page