Created
March 3, 2017 20:04
-
-
Save itsthejoker/420cb7dd7ba7fb669480a943f030e5b3 to your computer and use it in GitHub Desktop.
A miniature Python package to truly make your strings something special.
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
import string | |
def flip_char(char): | |
if char in string.ascii_lowercase: | |
return string.ascii_uppercase[string.lowercase.find(char)] | |
else: | |
return string.ascii_lowercase[string.uppercase.find(char)] | |
def beautify_string(old_string): | |
new_beautiful_string = [] | |
for num, letter in enumerate(old_string): | |
if letter in string.ascii_letters: | |
if num % 2: | |
new_beautiful_string.append(flip_char(letter)) | |
continue | |
new_beautiful_string.append(letter) | |
return "".join(new_beautiful_string) | |
if __name__ == '__main__': | |
demo = "This is the function that everyone wants and nobody needs" | |
result = beautify_string(demo) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment