From Camel to Snake

This is the reverse naming conversion: a joined CamelCase name needs to become a name with underscores. The function camel_to_snake receives a string in CamelCase. Add an underscore before each uppercase letter except the first one, then convert the whole result to lowercase.

Примеры

Ввод
"HelloWorld"
Вывод
"hello_world"
Ввод
"MyVarName"
Вывод
"my_var_name"
Ввод
"Single"
Вывод
"single"

Нужно реализовать

def camel_to_snake(s: str) -> str:

Теги

strings
PostgreSQLv16

Itt jelenik meg a kód futtatásának eredménye

Visible tests
1
Input
"HelloWorld"
Expected"hello_world"
2
Input
"MyVarName"
Expected"my_var_name"
3
Input
"Single"
Expected"single"
4
Input
""
Expected""
5
Input
"ABC"
Expected"a_b_c"
6
Input
" "
Expected" "
Focus radio
Paused · SomaFM · Fluid