Use inplace sort and generator expressions

(cherry picked from commit 87ce17df8b)
This commit is contained in:
Gouvernathor 2023-11-16 02:17:25 +01:00 committed by LoafyLemon
parent 675839d28e
commit 815c90109b

View File

@ -1,17 +1,17 @@
init python: init python:
def inventory_sortfilter(item, sortby="A-z", filtering=None): def inventory_sortfilter(item, sortby="A-z", filtering=None):
if filtering == "Owned": if filtering == "Owned":
item = [x for x in item if x.owned > 0] item = (x for x in item if x.owned > 0)
# Always sort alphabetically first. # Always sort alphabetically first.
item = sorted(item, key=lambda x: natsort_key(x.name)) item = sorted(item, key=lambda x: natsort_key(x.name))
if sortby == "z-A": if sortby == "z-A":
item = sorted(item, key=lambda x: natsort_key(x.name), reverse=True) item.sort(key=lambda x: natsort_key(x.name), reverse=True)
elif current_sorting == "Available": elif current_sorting == "Available":
item = sorted(item, key=lambda x: x.owned is True, reverse=True) item.sort(key=lambda x: x.owned is True, reverse=True)
elif current_sorting == "Unavailable": elif current_sorting == "Unavailable":
item = sorted(item, key=lambda x: x.owned is False) item.sort(key=lambda x: x.owned is False)
return item return item