import reinterval='4-6,10-12,16'l=[int(s) if all(c.isdigit() for c in s) else '-' for s in re.findall(r'\d+|-', interval)]print(l)
Standard input is empty
[4, '-', 6, 10, '-', 12, 16]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!