sort¶
Hook for sorting complex lists, dicts, or items within a key both in place or as output.
Inputs¶
Name | Type | Default | Required | Description |
---|---|---|---|---|
src | Union[list, dict, str] | True | Either a list of strings or a list of dicts to sort and return the output or a string key_path to sort both in place or as output (see in_place ). |
|
key | str | None | False | If the src is a list of maps, the key to sort the contents by. |
keys | list | [] | True | A list of fields to sort on for dict inputs based on priority. |
in_place | bool | True | True | If the src is a string (ie a key path), then sort the item in place (ie replace original) and return None. |
reverse | bool | False | True | To sort in reverse. |
src_is_key_path | bool | False | True | If the src is a list and is meant to be a key path. |
sep | str | / | True | For string src's, a separator for key path. |
index | Union[int, list] | None | False | If the input src is a list, use the index as the sort key. Takes both an int for single index or list for multiple criteria. |
Arguments¶
Position | Argument | Type |
---|---|---|
1 | src | Union[list, dict, str] |
2 | keys | list |
Returns¶
Union[list, dict, NoneType]
Examples¶
Sort a list in place based on a reference to a key path list or keys in dict
stuff:
things:
- foo
- bar
- baz
in-place_>: sort stuff/things # Notice this is a private hook
# Argument is a list so it is output to key
output->: sort {{stuff.things}}
stuff:
things:
- bar
- baz
- foo
output:
- bar
- baz
- foo