← Back to challenges

Convert camelCase to snake_case

PythonHardstringsregexformattinglanguage_fundamentals

Instructions

Create a function that takes a string of words (or just one word) and converts each word from camelCase to snake_case.

Examples

camel_to_snake("magicCarrots") ➞ "magic_carrots"

camel_to_snake("greatApples for aSmellyRhino") ➞ "great_apples for a_smelly_rhino"

camel_to_snake("thatsGreat") ➞ "thats_great"

Notes

You won't get more than two capitals in a row (e.g. "DIYFoods" is not given).

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.