given a sentence in camel case and want to convert to snake case using for loop and indexing
def camel_to_snake(camel_str):
snake_str = camel_str[0].lower()
for i in range(1, len(camel_str)):
char = camel_str[i]
if char.isupper():
snake_str += f'_{char.lower()}'
else:
snake_str += char
return snake_str
test_str = 'camelCase'
print(camel_to_snake(test_str))
Comments
Leave a comment