def to_snakecase(string):
 string = re.sub('(\\s)', (lambda match: '_'), string)
 string = re.sub('^(_*)([^_])', (lambda match: (match.group(1) + match.group(2).lower())), string)
 string = re.sub('(\\w*)([.]+)([A-Z])', (lambda match: ((match.group(1) + match.group(2)) + match.group(3).lower())), string)
 string = re.sub('(?<=[^_])_+([^_])', (lambda match: ('_' + match.group(1).lower())), string)
 return re.sub('[A-Z]', (lambda match: ('_' + match.group(0).lower())), string)

def to_snakecase ( string ) : string = re . sub ( '(\\s)' , ( lambda match : '_' ) , string ) string = re . sub ( '^(_*)([^_])' , ( lambda match : ( match . group ( 1 ) + match . group ( 2 ) . lower ( ) ) ) , string ) string = re . sub ( '(\\w*)([.]+)([A-Z])' , ( lambda match : ( ( match . group ( 1 ) + match . group ( 2 ) ) + match . group ( 3 ) . lower ( ) ) ) , string ) string = re . sub ( '(?<=[^_])_+([^_])' , ( lambda match : ( '_' + match . group ( 1 ) . lower ( ) ) ) , string ) return re . sub ( '[A-Z]' , ( lambda match : ( '_' + match . group ( 0 ) . lower ( ) ) ) , string )
converts the given string to snake-case .