Answer to Question #176597 in Python for adhi chinna

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".


1
Expert's answer
2021-04-01T16:02:54-0400
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"))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS