mirror of
https://github.com/rembo10/headphones.git
synced 2026-04-05 04:29:25 +01:00
11 lines
448 B
Python
11 lines
448 B
Python
def multikeysort(items, columns):
|
|
from operator import itemgetter
|
|
comparers = [ ((itemgetter(col[1:].strip()), -1) if col.startswith('-') else (itemgetter(col.strip()), 1)) for col in columns]
|
|
def comparer(left, right):
|
|
for fn, mult in comparers:
|
|
result = cmp(fn(left), fn(right))
|
|
if result:
|
|
return mult * result
|
|
else:
|
|
return 0
|
|
return sorted(items, cmp=comparer) |