How to convert the string from camel case to snake case using iterate over the words and using string slicing approximately
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)
return ''.join(result)
s = input("Enter a string in camel case: ")
print(camelToSnakeCase(s))
Comments
Leave a comment