Write down a python function to convert camel case to snake case?

PythonServer Side ProgrammingProgramming

Code for converting camel case to snake case is given below

import re
def convert(name):
      s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
      return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
print convert('JavaBeans')
print convert('JavaStrutsSwing')

OUTPUT

java_beans
java_struts_swing
raja
Published on 07-Dec-2017 12:19:16
Advertisements