easy +10 pts

Snake case to camel case

Convert snake_case strings to camelCase with proper handling of underscores.

Write a function `snake_to_camel(s: str) -> str` that takes a string in snake_case (words separated by underscores) and returns the corresponding camelCase string. The rules are: - The first word remains unchanged. - Each subsequent word is capitalized (first letter uppercase, rest lowercase as given). - All underscores are removed. - Input may contain leading or trailing underscores; these are removed and do not affect the result. - Consecutive underscores are treated as a single separator. - If the input is empty, return an empty string. Assume the string contains only lowercase letters, digits, and underscores, with words starting with a letter or digit. Examples: `"hello_world"` -> `"helloWorld"`, `"foo__bar"` -> `"fooBar"`, `"_leading_trailing_"` -> `"leadingTrailing"`.

Constraints

0 <= len(s) <= 1000. The input consists of lowercase letters a-z, digits 0-9, and underscores '_'.

Example

>>> snake_to_camel('hello_world')
'helloWorld'
>>> snake_to_camel('foo__bar')
'fooBar'
>>> snake_to_camel('_leading_trailing_')
'leadingTrailing'
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Split the string by underscore and filter out empty parts.
The first part stays as is; for each subsequent part, capitalize the first character and keep the rest.
Use `str.capitalize()` or `part[0].upper() + part[1:]`.
Remember to handle empty input.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.