I have a function mixrange which makes a string like '1,2,4-6,8' and converts it into '1,2,4,5,6,8'. Now how can I do the exact opposite where I have an input '1,2,4,5,6,8' and it converts it into '1,2,4-6,8'? The function type casts it to int and a list (which is not a problem as i can convert it back to a normal string).
def mixrange(s):
r = []
for i in s.split(','):
if '-' not in i:
r.append(int(i))
else:
l,h = map(int, i.split('-'))
r+= range(l,h+1)
return r