From 54d1ca3ebac0869ba41d85a508f346ced60467e4 Mon Sep 17 00:00:00 2001 From: jce <28319872+JasperCraeghs@users.noreply.github.com> Date: Mon, 25 Sep 2023 13:57:15 +0300 Subject: [PATCH] Sort naturally instead of alphabetically on attributes --- mlx/traceable_collection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mlx/traceable_collection.py b/mlx/traceable_collection.py index c34c258c..7defdd18 100644 --- a/mlx/traceable_collection.py +++ b/mlx/traceable_collection.py @@ -298,7 +298,7 @@ def get_items(self, regex, attributes=None, sortattributes=None, reverse=False, Args: regex (str/re.Pattern): Regex pattern or object to match the items in this collection against attributes (dict): Dictionary with attribute-regex pairs to match the items in this collection against - sortattributes (list): List of attributes on which to alphabetically sort the items + sortattributes (list): List of attributes on which to naturally sort the items reverse (bool): True for reverse sorting sort (bool): When sortattributes is falsy: True to enable natural sorting, False to disable sorting @@ -313,8 +313,8 @@ def get_items(self, regex, attributes=None, sortattributes=None, reverse=False, if item.is_match(regex) and (not attributes or item.attributes_match(attributes)): matches.append(itemid) if sortattributes: - return sorted(matches, key=lambda itemid: self.get_item(itemid).get_attributes(sortattributes), - reverse=reverse) + return natsorted(matches, key=lambda itemid: self.get_item(itemid).get_attributes(sortattributes), + reverse=reverse) elif sort: return natsorted(matches, reverse=reverse) return matches