 <p>Made my own version without itertools.</p> <pre><code>def expander(inpt): ret = [] for token in inpt.split(','): if '-' in token: a, b = token.strip().split('-') ret.extend(range(int(a), int(b)+1)) else: ret.append(int(token)) return ret print(expander('1, 3-4, 7-9')) </code></pre> <p>Keep in mind it would be healthy to check this string with regex.</p>