Answer to Question #204959 in Python for reddy prasanna

Question #204959

given a sentence in camel case and want to convert to snake case using for loop and indexing


1
Expert's answer
2021-06-09T07:43:37-0400
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))

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