From a0802dd66ebaa770854fd9e88ee34e4a1bc00582 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 22 Sep 2017 09:54:28 -0400 Subject: [PATCH] Add natural sort For output groups with equivalent node counts, sort naturally by the group text header. --- confluent_client/confluent/textgroup.py | 27 +++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/confluent_client/confluent/textgroup.py b/confluent_client/confluent/textgroup.py index 2960bbaa..18556d05 100644 --- a/confluent_client/confluent/textgroup.py +++ b/confluent_client/confluent/textgroup.py @@ -127,10 +127,21 @@ class GroupedData(object): self.generate_byoutput() modaloutput = None ismodal = True - outdatalist = sorted( - self.byoutput, key=lambda x: len(self.byoutput[x])) - if not reverse: - outdatalist = reversed(outdatalist) + + if reverse: + outdatalist = sorted( + self.byoutput, key=lambda x: [len(self.byoutput[x]), + humanify_nodename( + self.get_group_text( + self.byoutput[x] + ))]) + else: + outdatalist = sorted( + self.byoutput, key=lambda x: [0 - len(self.byoutput[x]), + humanify_nodename( + self.get_group_text( + self.byoutput[x] + ))]) if reverse and skipmodal: # if reversed, the last is biggest and should be skipped if modal outdatalist = outdatalist[:-1] @@ -157,8 +168,12 @@ class GroupedData(object): modaloutput = None ismodal = True revoutput = [] - for outdata in reversed( - sorted(self.byoutput, key=lambda x: len(self.byoutput[x]))): + for outdata in sorted( + self.byoutput, key=lambda x: [0 - len(self.byoutput[x]), + humanify_nodename( + self.get_group_text( + self.byoutput[x] + ))]): if modaloutput is None: modaloutput = outdata if skipmodal: