In Python remove() will remove the first occurrence of value in a list.
remove()
How to remove all occurrences of a value from a list?
This is w
for i in range(a.count(' ')): a.remove(' ')
Much simpler I believe.