How to remove whitespace in a list
<p>I can't remove my whitespace in my list. </p>

<pre><code>invoer = "5-9-7-1-7-8-3-2-4-8-7-9"
cijferlijst = []

for cijfer in invoer:
    cijferlijst.append(cijfer.strip('-'))
</code></pre>

<p>I tried the following but it doesn't work. I already made a list from my string and seperated everything but the <code>"-"</code> is now a <code>""</code>.  </p>

<pre><code>filter(lambda x: x.strip(), cijferlijst)
filter(str.strip, cijferlijst)
filter(None, cijferlijst)
abc = [x.replace(' ', '') for x in cijferlijst]
</code></pre>

<p>If you want the numbers in string without <code>-</code>, use <a href="https://docs.python.org/2/library/string.html#string.replace" rel="nofollow"><code>.replace()</code></a> as:</p>

<pre><code>&gt;&gt;&gt; string_list = "5-9-7-1-7-8-3-2-4-8-7-9"
&gt;&gt;&gt; string_list.replace('-', '')
'597178324879'
</code></pre>

<p>If you want the numbers as <code>list</code> of numbers, use <a href="https://docs.python.org/2/library/stdtypes.html#str.split" rel="nofollow"><code>.split()</code></a>: </p>

<pre><code>&gt;&gt;&gt; string_list.split('-')
['5', '9', '7', '1', '7', '8', '3', '2', '4', '8', '7', '9']
</code></pre>

python list