def preserve_spaces(txt):
 txt = re.sub('(?P<space>[ ]{2,})', (lambda mo: (' ' + ('&nbsp;' * (len(mo.group('space')) - 1)))), txt)
 txt = txt.replace(' DCTB ', '&nbsp;&nbsp;&nbsp;&nbsp;')
 return txt

def preserve_spaces ( txt ) : txt = re . sub ( '(?P<space>[ ]{2,})' , ( lambda mo : ( ' ' + ( '&nbsp;' * ( len ( mo . group ( 'space' ) ) - 1 ) ) ) ) , txt ) txt = txt . replace ( ' DCTB ' , '&nbsp;&nbsp;&nbsp;&nbsp;' ) return txt
replaces spaces multiple spaces with &nbsp; entities .