Created
September 30, 2018 16:34
-
-
Save stonecharioteer/a428a4343644d54786bb8e88ca209a27 to your computer and use it in GitHub Desktop.
gist to show how to get hiragana x romaji dictionary
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
def get_hiragana(): | |
"""Returns a dictionary of hiragana and their romaji.""" | |
import textwrap | |
data = u""" | |
a i u e o | |
∅ あ い う え お | |
k か き く け こ | |
s さ し す せ そ | |
t た ち つ て と | |
n な に ぬ ね の | |
h は ひ ふ へ ほ | |
m ま み む め も | |
y や ゆ よ | |
r ら り る れ ろ | |
w わ ゐ ゑ を | |
""" | |
hiragana_table = textwrap.dedent(data) | |
hiragana_dict = {} | |
for i in hiragana_table.split("\n"): | |
items = i.strip().split() | |
if len(items) == 5: | |
header = items | |
elif len(items) == 6: | |
key = items[0] | |
hiragana = items[1:] | |
for h, letter in zip(header, hiragana): | |
romaji = u"{}{}".format(key, h) | |
hiragana_dict[romaji] = letter | |
# also, need to add 'n' | |
hiragana_dict["n"] = u"ん" | |
return hiragana_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment