From 446d35d9c4fe86baed61f36fd3d41cbe31a313f3 Mon Sep 17 00:00:00 2001
From: Ewan Cook <5237234+ewancook@users.noreply.github.com>
Date: Wed, 8 Aug 2018 11:45:35 +0100
Subject: [PATCH] refs #23023 update hyphenise

---
 .../LoadWidget/load_utils.py                  | 28 +++++++++----------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/scripts/Muon/GUI/ElementalAnalysis/LoadWidget/load_utils.py b/scripts/Muon/GUI/ElementalAnalysis/LoadWidget/load_utils.py
index b434aa3b4b8..f3acfa59d04 100644
--- a/scripts/Muon/GUI/ElementalAnalysis/LoadWidget/load_utils.py
+++ b/scripts/Muon/GUI/ElementalAnalysis/LoadWidget/load_utils.py
@@ -127,19 +127,17 @@ def flatten_run_data(*workspaces):
 
 
 def hyphenise(vals):
-    vals = sorted(list(set(vals)))
-    pos, out = 0, []
-    l = len(vals)
-    for i in range(1, l):
-        last = (i == l - 1)
-        if vals[i] - vals[i - 1] != 1:
-            if i == 1 or pos == i - 1:
-                out.append(str(vals[pos]))
-            else:
-                out.append("{}-{}".format(vals[pos], vals[i - 1]))
-            if last:
-                out.append(str(vals[i]))
-            pos = i
-        elif last:
-            out.append("{}-{}".format(vals[pos], vals[i]))
+    if not len(vals):
+        return ""
+    vals = [str(s) for s in sorted(list(set(vals)))]
+    diffs = [int(vals[i + 1]) - int(vals[i]) for i in range(len(vals) - 1)]
+    a = b = vals[0]
+    out = []
+    for i, d in enumerate(diffs):
+        if d != 1:
+            out.append("-".join([a, b]) if a != b else a)
+            a = vals[i + 1]
+        b = vals[i + 1]
+        if i == len(diffs) - 1:
+            out.append("-".join([a, b]) if a != b else vals[i + 1])
     return ", ".join(out)
-- 
GitLab