#!/usr/bin/env python3 import functools import unicodedata XFORMS = { 0x00C6: "ae", 0x00E6: "ae", 0x0152: "oe", 0x0153: "oe", "æ": "ae", "Æ": "AE", } NORMALIZE = str.maketrans(XFORMS) def normalize(text): return nfc("".join(c for c in nfd(text.translate(NORMALIZE)) if not unicodedata.combining(c))) nfc = functools.partial(unicodedata.normalize, "NFC") nfd = functools.partial(unicodedata.normalize, "NFD") original = "The Ænid œvre" expected = "The AEnid oevre" actual = normalize(original) if actual != expected: print("BUG", (actual, "!=", expected)) else: print("OK", (actual, "==", expected))