Is there a way to get the Unicode Block of a character in python? The unicodedata module doesn’t seem to have what I need, and I couldn’t find an external library for it.
Basically, I need the same functionality as Character.UnicodeBlock.of() in java.
I couldn’t find one either. Strange!
Luckily, the number of Unicode blocks is quite manageably small.
This implementation accepts a one-character Unicode string, just like the functions in
unicodedata. If your inputs are mostly ASCII, this linear search might even be faster than binary search usingbisector whatever. If I were submitting this for inclusion in the Python standard library, I’d probably write it as a binary search through an array of statically-initializedstructs in C.