Answer to Question #302999 in Python for Nav

Question #302999

Given a string in camel case, write a python program to convert the given string from camel case to snake case

1
Expert's answer
2022-02-26T05:51:48-0500


SOLUTION CODE


from re import sub

def snake_case_funcion(s):
  return '_'.join(
    sub('([A-Z][a-z]+)', r' \1',
    sub('([A-Z]+)', r' \1',
    s.replace('-', ' '))).split()).lower()

camel_case_string = input("Enter a string in camel case: ")
print("The string in snake case is: ", snake_case_funcion(camel_case_string))



SAMPLE PROGRAM OUTPUT



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