Skip to content

Instantly share code, notes, and snippets.

@SnowyPainter
Created March 19, 2022 09:11
Show Gist options
  • Save SnowyPainter/add2ff771956c574f4f40069e21f1e81 to your computer and use it in GitHub Desktop.
Save SnowyPainter/add2ff771956c574f4f40069e21f1e81 to your computer and use it in GitHub Desktop.
뒤집어 재배열. 문장 부호 빼고
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