Skip to content

Instantly share code, notes, and snippets.

@FlamptX
Created July 7, 2021 20:59
Show Gist options
  • Save FlamptX/6a5bac513359a34b4c44e2855e5d251d to your computer and use it in GitHub Desktop.
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…
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"))
@FlamptX
Copy link
Author

FlamptX commented Jul 7, 2021

Pretty simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment