Case Flipper

This kind of text transformation is common when you need to scan a string and change each letter. Write a function to_alternating_case that takes a string string and inverts the case of every letter: lowercase becomes uppercase, and uppercase becomes lowercase. Spaces, digits, and other characters should stay unchanged.

Примеры

Ввод
"hello world"
Вывод
"HELLO WORLD"
Ввод
"HELLO WORLD"
Вывод
"hello world"
Ввод
"HeLLo WoRLD"
Вывод
"hEllO wOrld"

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

def to_alternating_case(string: str) -> str:

Теги

strings
PostgreSQLv16

Koodin suorituksen tulos näkyy tässä

Visible tests
1
Input
"hello world"
Expected"HELLO WORLD"
2
Input
"HELLO WORLD"
Expected"hello world"
3
Input
"HeLLo WoRLD"
Expected"hEllO wOrld"
4
Input
"1234"
Expected"1234"
5
Input
""
Expected""
6
Input
"4321"
Expected"4321"
Focus radio
Paused · SomaFM · Fluid