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

Something like this should do:

s = 'xxxxx - xxxxx'
space = ' '
nospace = ''
s = s.replace(space, nospace)
print s  # xxxxx-xxxxx
>>> s = 'XXXXX -\n\t XXXX'
>>> ''.join(s.split())
'XXXXX-XXXX'
>>>
commented: nice solution! +4