Intern — Middle
Case reversal in a string
livecode
Task condition
You need to write a function that takes a string and returns a new string where each alphabetic character is replaced with the character of the opposite case: lowercase letters become uppercase, and uppercase letters become lowercase. All other characters (digits, spaces, punctuation, etc.) are left unchanged.
Example
def toggle_case(text: str) -> str:
# implementation of the function
pass
Requirements
- The function should operate in O(n) time, where n is the length of the input string.
- Do not use built-in methods like
swapcase(or their equivalents) from standard libraries. - Preserve the original order of characters.
- Handle Unicode characters correctly, if the language allows.