Answer to Question #206189 in Python for siva

Question #206189

Case Conversion

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 "Python Learning" in camel case, your code should print given word in snake case "python_learning".

Sample Input 1

Python Learning

Sample Output 1

Python_learning




1
Expert's answer
2021-06-13T18:18:05-0400
def camelToSnakeCase(str):
    result = [str[0].lower()]
    for i in str[1:]:
        if i in ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
            result.append('_')
            result.append(i.lower())
        else:
            result.append(i)
    s=''.join(result)
    for i in s:
        s2=s.replace(" ","")
    return s2


s = input("Enter a string in camel case: ")
print(camelToSnakeCase(s))


Output


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