Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
CamelCase to SnakeCase
00:00
5 left

CamelCase to SnakeCase

EasyPython

Problem

Write a function to convert camelCase to snake_case. Implement def camel_to_snake(name):, where name is a non-empty string containing English letters in camelCase or PascalCase form, and return a new string with an underscore before every uppercase letter except the first, followed by lowercase conversion. For example, camelCase becomes camel_case, and PascalCase becomes pascal_case.

Constraints

  • 1 <= len(name) <= 10^4
  • name contains only English alphabetic characters
  • name follows camelCase or PascalCase formatting

Function Signature

def camel_to_snake(name):
Interviewer

Your question is CamelCase to SnakeCase. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.