Andrew Breza

24%
Flag icon
If you work with text from many languages, you may want to apply unicode.normalize('NFC', s) to any string s before comparing or storing it. If you do that often, it’s handy to have an nfc function to do so, as in Example 7-17. Example 7-17. Building a convenient Unicode normalizing function with partial >>> import unicodedata, functools >>> nfc = functools.partial(unicodedata.normalize, 'NFC') >>> s1 = 'café' >>> s2 = 'cafe\u0301' >>> s1, s2 ('café', 'café') >>> s1 == s2 False >>> nfc(s1) == nfc(s2) True
Fluent Python: Clear, Concise, and Effective Programming
Rate this book
Clear rating
Open Preview