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.
s = "2,5,7-9,12" ranges = (x.split("-") for x in s.split(",")) print [i for r in ranges for i in range(int(r[0]), int(r[-1]) + 1)]
prints
[2, 5, 7, 8, 9, 12]