"""
def wrapped(env, context, value):
expr = lambda x: env.get_attribute(x, attribute)
- rv = [{
+ return [{
'grouper': a,
'list': list(b)
- } for a, b in groupby(sorted(value, key=expr), expr)]
- rv.sort()
- return rv
+ } for a, b in sorted(groupby(sorted(value, key=expr), expr))]
return wrapped
try:
sorted = sorted
except NameError:
- def sorted(seq, reverse=False):
+ _cmp = cmp
+ def sorted(seq, cmp=None, key=None, reverse=False):
rv = list(seq)
- rv.sort()
+ if key is not None:
+ cmp = lambda a, b: _cmp(key(a), key(b))
+ rv.sort(cmp)
if reverse:
rv.reverse()
return rv