Skip to content
Myr

document that sort is stable

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Todd Lewis · committed by David Lord · parent 47e5c95 · Browse files · 1 file+13 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+13 added−2 removed

  • other:+13 added−2 removed

1 file+13 added−2 removed

modified:jinja2/filters.py+13 added-2 removed
282 unmodified lines
283def do_sort(284 environment, value, reverse=False, case_sensitive=False, attribute=None285):286 """Sort an iterable. Per default it sorts ascending, if you pass it287 true as first argument it will reverse the sorting.287 true as first argument it will reverse the sorting. The sort is stable,288 i.e. it guarantees not to change the relative order of elements that289 compare equal.290291 If the iterable is made of strings the third parameter can be used to292 control the case sensitiveness of the comparison which is disabled by293 default.
12 unmodified lines
306 {% for item in iterable|sort(attribute='date') %}307 ...308 {% endfor %}309310 Because the sort is stable, it is possible to chain sorts on different311 attributes and ordering:312313 .. sourcecode:: jinja314315 {% for item in iterable|sort(attribute='name')|sort(true,attribute='date') %}316 ...317 {% endfor %}318319 .. versionchanged:: 2.6320 The `attribute` parameter was added.321 The attribute parameter can contain multiple comma separated311 attributes, e.g. attr1,attr2.322 attributes, e.g. 'attr1,attr2', all subject to the same ordering.323 """324 key_func = make_multi_attrgetter(325 environment, attribute,326 postprocess=ignore_case if not case_sensitive else None
944 unmodified lines