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
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
Comments
Leave a comment