Unfolding the lists
.py
Unfold the list with ranges, sort and regroup
= ['12-15', '40003', '40012', '71842-71844', '71848-71851',
o '71853-54', '72717-72721', '72724-72732', '72734', '72787',
'68344', '46', '48', '49', '68351-68354', '68358', '59',
]
def r(s):
if '-' in s:
= map(int, s.split('-'))
a, b if b < a:
= map(str, (a, b))
sa, sb = map(len, (sa, sb))
la, lb = sa[:la-lb] + sb
sb = int(sb)
b return list(range(a, b+1))
else:
return [int(s),]
def r2(q):
= q.pop()
b while True:
try:
= b
a = None
prev
= q.pop()
b
= a
prev while (b == prev + 1):
= b
prev = q.pop()
b
if prev and a!=prev:
yield '-'.join(map(str, (a, prev)))
else:
yield str(a)
except IndexError:
if prev and a!=prev:
yield '-'.join(map(str, (a, prev)))
return
else:
yield str(a)
return
= []
z for x in o:
z.extend(r(x))
for i in range(len(z) - 1):
= z[i], z[i+1]
a, b if a>1000 and b < 1000:
= map(str, (a, b))
sa, sb = map(len, (sa, sb))
la, lb = sa[:la-lb] + sb
sb = int(sb)
b +1] = b
z[i
# We have a full unwrapped list here (z)
= sorted(set(z))
z1 # Saved to z1
= sorted(set(z), reverse=True)
z
= list(r2(z))
z2 # So we have new folded list here (z2)