Question #176597

Given a string in camel case, write a python program to convert the given string from camel case to snake case.Input


The input will be a single line contain a string.Output


The output should contain the given word in snake case.Explanation


For example, if the given word is "PythonLearning" in camel case, your code should print given word in snake case "python_learning".


Expert's answer

def camel2snake(name):
    n = []
    for c in name:
        if c == name[0]:
            n.append(c.lower())
        else:
            if(c.isupper()):
                c = c.lower()
                c = "_"+c
                n.append(c)
            else:
                n.append(c)
    s = ""
    for e in n:
        s += e 
    return s
                
print(camel2snake("PigeonHole"))
LATEST TUTORIALS
APPROVED BY CLIENTS