Created
June 20, 2021 02:01
-
-
Save tsuyukimakoto/7a7c2b23be4850c27d6de0c0b001d646 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
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