Skip to content

Instantly share code, notes, and snippets.

@RHDZMOTA
Last active November 10, 2021 19:13
Show Gist options
  • Save RHDZMOTA/ed676de4927ccbfe189d11c1084616ad to your computer and use it in GitHub Desktop.
Save RHDZMOTA/ed676de4927ccbfe189d11c1084616ad to your computer and use it in GitHub Desktop.
Swap-case in Python without using the swapcase built-in method.
# Challenge: implement swapcase without using the built-in method
def swapcase(string: str) -> str:
return "".join(
char.lower() if char.isupper() else char.upper()
for char in string
)
assert swapcase("AbCd") == "aBcD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment