How can I generate a list and flatten it the same time in python?
<p>This is more of a refactoring question, as the code works as is. But since I am still learning <code>Python</code>, I thought there would be a better way to do this, and I spent a few hours now digging into the other possibilities, but can't get anywhere.</p>

<p>So I have the following statement:</p>

<p><code>numbers = [re.split(' ?- ?', ticket.text.strip()) for ticket in tickets]</code></p>

<p>which obviously generates a list of lists. However, I want to have just a single list of the numbers taken out from that regex.</p>

<p>So this is the second line of code that flattens the above list (I found this solution here, on <code>StackOverflow</code> btw):</p>

<p><code>flat = [item for setlist in numbers for item in setlist]</code></p>

<p>Main thing I am trying to achieve is to have this on 1 single line. Otherwise, I could of course have a normal <code>for .. in</code> loop, that would append each number to numbers list, but I like keeping it on 1 line. </p>

<p>If this is the best it can get, I would also love to know that please.. :)</p>

<pre><code>sum([re.split(' ?- ?', ticket.text.strip()) for ticket in tickets], [])
</code></pre>

python