Answer to Question #186737 in Python for Vivek Reddy

Question #186737

The given question is (Given a string in camel case, write a python program to convert the given string from camel case to snake case.)

Given inputs

  1. PythonLearning output should be python_learning
  2. CamelCase output should be camel_case


I need code and explanation for this question........?



1
Expert's answer
2021-04-28T09:50:47-0400
# Camel word input
CamelStr = input('Enter a string in camel notation: ')
# Create an empty letter list of a word in snake notation
letters=[]
# We iterate through all the letters of the earlier 
# entered word letter by letter
for letter in CamelStr:
# If an uppercase character is encountered, add _
    if letter.isupper():
        letters.append('_')
# Add small letters to the list
    letters.append(letter.lower())
# If the initial character in the list is _ then remove it
if letters[0] == '_':
    letters.pop(0)
# Convert the list to a string and print
snake_str =''.join(letters)
print(snake_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

sandy
20.09.22, 13:14

code working!!!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS