Let's say I have the following array of dicts:
>>> a =[{'md5': 'abc', 'title': 'something'}, {'md5': 'zyx', 'title': 'something'}]
I can sort on the strings ascending as-is:
>>> sorted(a, key=lambda x: (x['title'], x['md5']))
[{'md5': 'abc', 'title': 'something'}, {'md5': 'zyx', 'title': 'something'}]
However, it appears I cannot do it in-line descendingly:
>>> sorted(a, key=lambda x: (x['title'], -x['md5']))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <lambda>
TypeError: bad operand type for unary -: 'str'
Is there a way to do this within the sorted(iterator, key=...)
structure or what is the best way to do this?