test/apps/util/natsort.py
zakhy b01230ab06 Добавил сортировку по алфавиту.
Сначала по кириллице, потом по латинице
2025-04-01 10:01:14 +07:00

18 lines
470 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
def natural_sort_key(s):
"""Функция для получения ключа для натуральной сортировки."""
return [
int(text) if text.isdigit() else text.lower() for text in
re.split(r"(\d+)", s)
]
def get_priority(text: str) -> (int, str):
if re.search('[а-яё]', text, flags=re.IGNORECASE):
return 2, text
if re.search('[a-z]', text, flags=re.IGNORECASE):
return 3, text