prize18-6 Exercise 2: Composition Does Not Change Clusters =========================================================== Predictions: three Hangul syllables are 3 code points in NFC and 8 in NFD (the three syllables split into 3 + 3 + 2 jamo), but 3 clusters either way. "a", CR LF, "b" is 4 code points and 3 clusters. A letter followed by two combining marks is one cluster; a combining mark before any letter has nothing to attach to, so it is a cluster of its own, and the letter after it another: 2 clusters. ex2.py (needs the third-party regex module): import regex import unicodedata as ud hangul = "\ud55c\uad6d\uc5b4" # three syllables for form in ["NFC", "NFD"]: s = ud.normalize(form, hangul) print(form, len(s), len(regex.findall(r"\X", s))) crlf = "a\r\nb" print(len(crlf), len(regex.findall(r"\X", crlf))) print(len(regex.findall(r"\X", "e\u0301\u0323")), len(regex.findall(r"\X", "\u0301e"))) Real output (Python 3.14): NFC 3 3 NFD 8 3 4 3 1 2 All as predicted. The key point is that the cluster rules are written in terms of properties of the code points, so a precomposed syllable and its decomposed spelling land in the same place; normalization changes code point counts but not what the reader sees.