Created
March 19, 2022 09:11
-
-
Save SnowyPainter/add2ff771956c574f4f40069e21f1e81 to your computer and use it in GitHub Desktop.
뒤집어 재배열. 문장 부호 빼고
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 invert(str): | |
result = list(str) | |
j = len(str)-1 | |
for i in range(0, len(str)): | |
if(str[i] in string.punctuation or str[i] == ' '): | |
continue | |
k = 0 | |
while(result[j-k] in string.punctuation or result[j-k] == ' '): | |
k += 1 | |
if(str[j-k].isupper()): | |
result[j-k] = str[i].upper() | |
else: | |
result[j-k] = str[i].lower() | |
j = j-k-1 | |
return ''.join(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment