#NEWLINE# @ environmentfilter #NEWLINE# def do_groupby( environment , value , attribute ) : #NEWLINE# #INDENT# "Group a sequence of objects by a common attribute.\n\n    If you for example have a list of dicts or objects that represent persons\n    with `gender`, `first_name` and `last_name` attributes and you want to\n    group all users by genders you can do something like the following\n    snippet:\n\n    .. sourcecode:: html+jinja\n\n        <ul>\n        {% for group in persons|groupby('gender') %}\n            <li>{{ group.grouper }}<ul>\n            {% for person in group.list %}\n                <li>{{ person.first_name }} {{ person.last_name }}</li>\n            {% endfor %}</ul></li>\n        {% endfor %}\n        </ul>\n\n    Additionally it's possible to use tuple unpacking for the grouper and\n    list:\n\n    .. sourcecode:: html+jinja\n\n        <ul>\n        {% for grouper, list in persons|groupby('gender') %}\n            ...\n        {% endfor %}\n        </ul>\n\n    As you can see the item we're grouping by is stored in the `grouper`\n    attribute and the `list` contains all the objects that have this grouper\n    in common.\n\n    .. versionchanged:: 2.6\n       It's now possible to use dotted notation to group by the child\n       attribute of another attribute.\n    " #NEWLINE# expr = make_attrgetter ( environment , attribute ) #NEWLINE# return sorted ( map ( _GroupTuple , groupby ( sorted ( value , key = expr ) , environment ) ) )