Created
July 7, 2021 20:59
-
-
Save FlamptX/6a5bac513359a34b4c44e2855e5d251d to your computer and use it in GitHub Desktop.
The swapcase function takes a string as an argument, then makes a list of it's characters, loops through them and if a character is a digit it will just skip the iteration, but if it's a letter and it's lowercase then it saves it as uppercase and if it's uppercase then it saves it as lowercase. And the end it joins the list into a string and ret…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def swapcase(string: str): | |
chars = list(string) | |
i = 0 | |
for x in chars: | |
if x.isdigit(): | |
continue | |
if x.islower(): | |
chars[i] = x.upper() | |
else: | |
chars[i] = x.lower() | |
i += 1 | |
return "".join(chars) | |
print(swapcase("PythoN")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty simple.