Python: How to make a string to a list using a substring?
<p>For example I have a string like this...</p>

<pre><code>StringA = "a city a street a room a bed"
</code></pre>

<p>I want to cut this string using a substring <code>"a "</code> and make a <code>list</code> from it. So the result looks like...</p>

<pre><code>ListA = ["city ", "street " ,"room " ,"bed"]
</code></pre>

<p>It would be OK if there are some empty spaces left. How can I do this? Thanks!</p>

<p>This will make list from string:</p>

<pre><code>re.split(r'\s*\ba\b\s*', a)
</code></pre>

<p>Output should be something like this:</p>

<pre><code>['', 'city', 'cola', 'room', 'bed']
</code></pre>

<p>So, to remove empty strings from list You can use:</p>

<pre><code>[item for item in re.split(r'\s*\ba\b\s*', a) if item]
</code></pre>

<p>Which will produce:</p>

<pre><code>['city', 'cola', 'room', 'bed']
</code></pre>

python