0

I would like to collapse whitespace in a string of the followinf foramat using a some pre defined functionalities.

XXXXX<space>-<space>XXXX shoud be converted to XXXXX-XXXXX
XXXXX<space>-XXXXX shoud be converted to XXXXX-XXXXX

Please help

4
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by dinilkarun
0

Something like this should do:

s = 'xxxxx - xxxxx'
space = ' '
nospace = ''
s = s.replace(space, nospace)
print s  # xxxxx-xxxxx
1
>>> s = 'XXXXX -\n\t XXXX'
>>> ''.join(s.split())
'XXXXX-XXXX'
>>>
Votes + Comments
nice solution!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.