Answer to Question #206078 in Python for Siva

Question #206078


How to convert the string from camel case to snake case using iterate over the words and using string slicing approximately


1
Expert's answer
2021-06-11T14:11:22-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)
     
    return ''.join(result)
     


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

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