def to_spacecase(string):
 string = re.sub('(_)', ' ', string)
 string = re.sub('^(\\s*)(.)', (lambda match: match.group(2).upper()), string)
 string = re.sub('(\\s*)$', '', string)
 string = re.sub('(?<=[^\\s])\\s+([^\\s])', (lambda match: (' ' + match.group(1).upper())), string)
 return re.sub('(?<=[^\\s])([A-Z])', (lambda match: (' ' + match.group(1))), string)

def to_spacecase ( string ) : string = re . sub ( '(_)' , ' ' , string ) string = re . sub ( '^(\\s*)(.)' , ( lambda match : match . group ( 2 ) . upper ( ) ) , string ) string = re . sub ( '(\\s*)$' , '' , string ) string = re . sub ( '(?<=[^\\s])\\s+([^\\s])' , ( lambda match : ( ' ' + match . group ( 1 ) . upper ( ) ) ) , string ) return re . sub ( '(?<=[^\\s])([A-Z])' , ( lambda match : ( ' ' + match . group ( 1 ) ) ) , string )
converts the given string to space-case .