prize18-9 Exercise 1: Spotting Mixed Scripts ============================================= Plan: take the first word of each letter's Unicode name (LATIN, GREEK, CYRILLIC ...) as its script. An ASCII-only string is trivially single script; a string with letters from two scripts is mixed and worth rejecting for something like a user name. ex1.py: import unicodedata as ud def scripts(s): return sorted({ud.name(c).split()[0] for c in s if c.isalpha()}) names = ["google", "g\u03bfogle", "g\u043e\u043egle", "\u0433\u0443\u0433\u043b", "caf\u00e9", "x1"] for n in names: sc = scripts(n) verdict = "ascii-only" if n.isascii() else ("single script" if len(sc) == 1 else "MIXED") print(f"{ascii(n):34} {sc!s:24} {verdict}") Real output (Python 3.14): 'google' ['LATIN'] ascii-only 'g\u03bfogle' ['GREEK', 'LATIN'] MIXED 'g\u043e\u043egle' ['CYRILLIC', 'LATIN'] MIXED '\u0433\u0443\u0433\u043b' ['CYRILLIC'] single script 'caf\xe9' ['LATIN'] single script 'x1' ['LATIN'] ascii-only The Greek omicron and the Cyrillic o's are caught because they sit among Latin letters. The all-Cyrillic name passes: it is a single script, and a name made entirely of Cyrillic look-alikes of Latin letters (for example one that visually reads as a Latin word) would pass too. That is the limit of a script check: it finds mixing but not whole-script confusables; the UTS #39 skeleton comparison is designed for those. This sketch also uses the first word of the character name, which is a rough stand-in for the Script_Extensions property.