1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | """ input: "AO6U.3JI3AO6WU/ EJI45K45J/3RU8 AU4Z; G4" output: (ㄇㄟˊ)(ㄧㄡˇ)(ㄨㄛˇ)(ㄇㄟˊ)(ㄊㄧㄥˉ)(ㄍㄨㄛˋ)(ㄓㄜˋ)(ㄓㄨㄥˇ)(ㄐㄧㄚˉ)(ㄇㄧˋ)(ㄈㄤˉ)(ㄕˋ) """ import re en = '1234567890-qwertyuiopasdfghjkl;zxcvbnm,./ ' zh = 'ㄅㄉˇˋㄓˊ˙ㄚㄞㄢㄦㄆㄊㄍㄐㄔㄗㄧㄛㄟㄣㄇㄋㄎㄑㄕㄘㄨㄜㄠㄤㄈㄌㄏㄒㄖㄙㄩㄝㄡㄥˉ' pure_zh = 'ㄅㄉㄓㄚㄞㄢㄦㄆㄊㄍㄐㄔㄗㄧㄛㄟㄣㄇㄋㄎㄑㄕㄘㄨㄜㄠㄤㄈㄌㄏㄒㄖㄙㄩㄝㄡㄥ' pron_zh = 'ˇˋˊ˙ˉ' d = {e:z for e, z in zip(en, zh)} while (k := input()) != '': k = k.lower() a = ''.join([d[i] for i in k]) a = re.sub(f'([{pure_zh}]+[{pron_zh}])', r'(\1)', a) print(a) |
Direct link: https://paste.plurk.com/show/im9mfPlidL9kcQTyBlCe