[go: up one dir, main page]

File: collation.py

package info (click to toggle)
cozy 1.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,140 kB
  • sloc: python: 8,014; xml: 392; makefile: 2
file content (15 lines) | stat: -rw-r--r-- 348 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import re


def collate_natural(s1, s2):
    if s1 == s2:
        return 0

    convert = lambda text: int(text) if text.isdigit() else text.lower()
    alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
    list = sorted([s1, s2], key=alphanum_key)

    if list.index(s1) == 0:
        return -1
    else:
        return 1