Skip to content

Instantly share code, notes, and snippets.

@editionc18
Created January 29, 2022 13:12
Show Gist options
  • Save editionc18/0ebf3b3016582485dc2db077a3be1f58 to your computer and use it in GitHub Desktop.
Save editionc18/0ebf3b3016582485dc2db077a3be1f58 to your computer and use it in GitHub Desktop.
import re
vowels5 = {'.ㅡㅣ.ㅣ': 'ㅙ', 'ㅡ..ㅣㅣ': 'ㅞ'}
vowels4 = {'ㅣ..ㅣ': 'ㅒ', '..ㅣㅣ': 'ㅖ', '.ㅡㅣ.': 'ㅘ', 'ㅡ..ㅣ': 'ㅝ'}
vowels3 = {'.ㅣㅣ': 'ㅔ', 'ㅣ.ㅣ': 'ㅐ', 'ㅣ..': 'ㅑ', '..ㅣ': 'ㅕ', '.ㅡㅣ': 'ㅚ', '..ㅡ': 'ㅛ', 'ㅡ.ㅣ': 'ㅟ', 'ㅡ..': 'ㅠ'}
vowels2 = {'ㅣ.': 'ㅏ', '.ㅣ': 'ㅓ', '.ㅡ': 'ㅗ', 'ㅡ.': 'ㅜ', 'ㅡㅣ': 'ㅢ'}
a = input()
a = a.replace("00","ㅁ")
a = a.replace("444", "ㄲ")
a = a.replace("55", "ㄹ")
a = a.replace("666", "ㄸ")
a = a.replace("777", "ㅃ")
a = a.replace("888", "ㅆ")
a = a.replace("999", "ㅉ")
a = a.replace("0", "ㅇ")
a = a.replace("44", "ㅋ")
a = a.replace("5", "ㄴ")
a = a.replace("66", "ㅌ")
a = a.replace("77", "ㅍ")
a = a.replace("88", "ㅎ")
a = a.replace("99", "ㅊ")
a = a.replace("4", "ㄱ")
a = a.replace("6", "ㄷ")
a = a.replace("7", "ㅂ")
a = a.replace("8", "ㅅ")
a = a.replace("9", "ㅈ")
a = a.replace("1", "ㅣ")
a = a.replace("2", ".")
a = a.replace("3", "ㅡ")
a = a.replace(" ", " ")
for k, v in vowels5.items():
a = a.replace(k, v)
for k, v in vowels4.items():
a = a.replace(k, v)
for k, v in vowels3.items():
a = a.replace(k, v)
for k, v in vowels2.items():
a = a.replace(k, v)
a = a.replace("ㄱㅅ", "ㄳ")
a = a.replace("ㄴㅈ", "ㄵ")
a = a.replace("ㄴㅎ", "ㄶ")
a = a.replace("ㄹㄱ", "ㄺ")
a = a.replace("ㄹㅁ", "ㄻ")
a = a.replace("ㄹㅂ", "ㄼ")
a = a.replace("ㄹㅅ", "ㄽ")
a = a.replace("ㄹㅌ", "ㄾ")
a = a.replace("ㄹㅍ", "ㄿ")
a = a.replace("ㄹㅎ", "ㅀ")
a = a.replace("ㅂㅅ", "ㅄ")
letter_regex = re.compile(r'[ㄱ-ㅎ][ㅏ-ㅣ](?:[ㄱ-ㅎ](?![ㅏ-ㅣ]))?')
words = a.split(' ')
for i in range(len(words)):
letters = letter_regex.findall(words[i])
for j in range(len(letters)):
if len(letters[j]) == 2:
letters[j] += ' '
cho = "ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ".index(letters[j][0])
jung = "ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ".index(letters[j][1])
jong = " ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ".index(letters[j][2])
letters[j] = chr(44032+ (cho * 21 + jung) * 28 + jong).encode('utf-8').decode('utf-8')
words[i] = ''.join(letters)
print(' '.join(words))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment