import re from functools import reduce ROM_MAPPING = { "y": "j", "ü": "yu", "öi": "eoi", "ö": "oe", "a": "aa", "ä": "a", "æ": "ae", } def rom_map(jyutping): return re.sub( "(g|k)u(?!ng|k)", "\\1wu", reduce(lambda pron, rule: pron.replace(*rule), ROM_MAPPING.items(), jyutping), ) converted = rom_map("") print(converted)