easy +8 pts

Split on camelCase

Split a camelCase string into a list of lowercase words.

Write a function `split_on_camel_case(s: str) -> list[str]` that takes a camelCase string and splits it into its constituent words. The input consists of one or more words joined together in camelCase style: the first word is all lowercase, and each subsequent word begins with an uppercase letter followed by lowercase letters. The function should return a list of the words, each in lowercase. For example, `split_on_camel_case("helloWorld")` should return `["hello", "world"]`. Assume the input is non-empty and contains only letters (a-z and A-Z). The input will never have two uppercase letters in a row.

Constraints

Input `s` is a non-empty string consisting only of English letters. The first character is always lowercase. Uppercase letters appear only at the start of new words. Length of `s` is at most 1000.

Example

>>> split_on_camel_case("helloWorld")
['hello', 'world']
>>> split_on_camel_case("thisIsATest")
['this', 'is', 'a', 'test']
>>> split_on_camel_case("camel")
['camel']
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Loop through characters and start a new word when you see an uppercase letter.
You can collect characters into a temporary word and append it to the result when you hit an uppercase letter.
Remember to append the last word after the loop.
Use `lower()` to convert each word to lowercase.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.