Commit 9fd5acf7 authored by Régis Witz's avatar Régis Witz
Browse files

️ improve reference sorting in lexicon

parent d2bcda6a
......@@ -54,7 +54,7 @@ def compare_references(x, y):
return -1
if not y:
return 1
size = len(x) if len(x) < len(y) else len(y)
size = min(len(x), len(y))
for i in range(0, size):
try:
res = int(x[i]) - int(y[i])
......@@ -62,9 +62,19 @@ def compare_references(x, y):
continue
return res
except ValueError:
# things like 'EA', '909C' or '279-290'
sx = str(x[i])
sy = str(y[i])
from itertools import takewhile
dx = ''.join(takewhile(str.isdigit, sx))
dy = ''.join(takewhile(str.isdigit, sy))
if dx and dy: # stuff like '909C' or '279-290'
try:
res = int(dx) - int(dy)
if res != 0:
return res
except ValueError:
pass # probably something like '1²'
# stuff like 'EA'
if sx == sy:
continue
if sx < sy:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment