How can i easily handle numberseries formated with brackets?
<p>I have a long list of numberseries formated like this:</p>

<pre><code>["4450[0-9]", "6148[0-9][0-9]"]
</code></pre>

<p>I want to make a list from one of those series with single numbers:</p>

<pre><code>[44500,44501,..., 44509]
</code></pre>

<p>i need to do this for many series within the original list and i'm wondering what the best way is for doing that?</p>

<p>Probably not the best solution, but you can approach it recursively looking for the <code>[x-y]</code> ranges and <a href="https://wiki.python.org/moin/Generators" rel="nofollow">generating</a> values (using <code>yield</code> and <a href="https://docs.python.org/3/whatsnew/3.3.html#pep-380" rel="nofollow"><code>yield from</code></a> in this case, hence for Python 3.3+):</p>

<pre><code>import re

pattern = re.compile(r"\[(\d+)-(\d+)\]")

def get_range(s):
    matches = pattern.search(s)
    if not matches:
        yield int(s)
    else:
        start, end = matches.groups()
        for i in range(int(start), int(end) + 1):
            repl = pattern.sub(str(i), s, 1)
            yield from get_range(repl)


for item in get_range("6148[0-9][0-9]"):
    print(item)
</code></pre>

<p>Prints:</p>

<pre><code>614800
614801
...
614898
614899
</code></pre>

python numbers series number-sequence