Python 3.8+unicodedatafunction
unicodedata.is_normalized()
normalization
Checks whether a string is already in the given normal form, faster than calling normalize() and comparing.
Syntax
unicodedata.is_normalized(form, unistr, /)
Often the answer comes without building a new string, which is why it is called before normalize() on large texts. The form is mandatory: a two-code-point 'й' is False for 'NFC' but True for 'NFD', so 'normalized' means nothing without a form. It never changes the string; it was added in 3.8.
Examples
import unicodedata
s = 'и\u0306' # й из двух кодовых точек
print(unicodedata.is_normalized('NFC', s), unicodedata.is_normalized('NFD', s)) # → False True
if not unicodedata.is_normalized('NFC', s):
s = unicodedata.normalize('NFC', s)
print(len(s)) # → 1
See also
Open in the full glossarydocs.python.orgReport an inaccuracy