Skip to content

Instantly share code, notes, and snippets.

@tsuyukimakoto
Created June 20, 2021 02:01
Show Gist options
  • Save tsuyukimakoto/7a7c2b23be4850c27d6de0c0b001d646 to your computer and use it in GitHub Desktop.
Save tsuyukimakoto/7a7c2b23be4850c27d6de0c0b001d646 to your computer and use it in GitHub Desktop.
数字・アルファベット・+-を全角から半角に変換(他の文字はそのまま)
ALNUM_ZEN = ("0123456789"
"ABCDEFGHIJ"
"KLMNOPQRST"
"UVWXYZ"
"abcdefghij"
"klmnopqrst"
"uvwxyz"
"+ー")
ALNUM_HAN = ("0123456789"
"ABCDEFGHIJ"
"KLMNOPQRST"
"UVWXYZ"
"abcdefghij"
"klmnopqrst"
"uvwxyz"
"+-")
ZEN_HAN_TABLE = str.maketrans(ALNUM_ZEN, ALNUM_HAN)
def convert_alnum_zenhan(target):
assert type(target) == str
return target.translate(ZEN_HAN_TABLE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment