I know this has already been answered, but if you end doing this a lot, regular expressions may be a better way to go:
>>> import re
>>> re.sub(r'\s', '', string).split(',')
['blah', 'lots', 'of', 'spaces', 'here']
The \s
matches any whitespace character, and we just replace it with an empty string ''
. You can find more info here: http://docs.python.org/library/re.html#re.sub