How to get rid of space in a string in python? -


i trying take string in list of strings , remove white space while separating non-space comma. example have string:

'        xx       xx          x   xxxxxx   xx               xxxxxxx    xxxxx' 

and need return ['xx', 'xx', 'x', 'xxxxxx', 'xx', 'xxxxxxx', 'xxxxx']. suggestions?

note: amount of space between each segment varies.

use str.split(), exactly need already, splitting on arbitrary-width whitespace:

>>> example = '        xx       xx          x   xxxxxx   xx               xxxxxxxx    xxxxx' >>> example.split() ['xx', 'xx', 'x', 'xxxxxx', 'xx', 'xxxxxxxx', 'xxxxx'] 

note leading whitespace has been removed well.

quoting documentation:

if sep not specified or none, different splitting algorithm applied: runs of consecutive whitespace regarded single separator, , result contain no empty strings @ start or end if string has leading or trailing whitespace. consequently, splitting empty string or string consisting of whitespace none separator returns [].


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -