Answer to Question #348542 in Python for Mani Krishna

Question #348542

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


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
2022-06-06T08:57:14-0400
def cameltosanke(str):
    res = [str[0]]
    for c in str[1:]:
        if c in ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
            res.append('_')
            res.append(c)
        else:
            res.append(c)

    return ''.join(res)

str = input()
print(cameltosanke(str))

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