def f(x):
    result = []
for part in x.split(','):
    if '-' in part:
        a, b = part.split('-')
a, b = int(a), int(b)
result.extend(list(range(a, b + 1)))
How to convert numeric string ranges to a list in Python