I have \"2,5,7-9,12\" string.
\"2,5,7-9,12\"
I want to get [2, 5, 7, 8, 9, 12] list from it.
Is there any built-in function for it in python?
Thanks.
I would define function:
def make_range(s): out = [] s = s.split(',') for n in s: if '-' in n: n = n.split('-') for i in range(int(n[0]), int(n[1]) + 1): out.append(i) else: out.append(int(n)) return out print make_range("2,5,7-9,12") #output [2, 5, 7, 8, 9, 12]