WebHost: use title-typical sorting for game titles (#883)

This commit is contained in:
Fabian Dill
2022-08-09 22:21:45 +02:00
committed by GitHub
parent debda5d111
commit f2e83c37e9
4 changed files with 16 additions and 2 deletions

View File

@@ -603,3 +603,14 @@ def messagebox(title: str, text: str, error: bool = False) -> None:
root.withdraw()
showerror(title, text) if error else showinfo(title, text)
root.update()
def title_sorted(data: typing.Sequence, key=None, ignore: typing.Set = frozenset(("a", "the"))):
"""Sorts a sequence of text ignoring typical articles like "a" or "the" in the beginning."""
def sorter(element: str) -> str:
parts = element.split(maxsplit=1)
if parts[0].lower() in ignore:
return parts[1]
else:
return element
return sorted(data, key=lambda i: sorter(key(i)) if key else sorter(i))