Created
May 26, 2012 09:08
-
-
Save mitchellrj/2793033 to your computer and use it in GitHub Desktop.
Normalized cmp for sorting lists of strings with accents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unicodedata | |
def normalized_cmp(x, y): | |
if isinstance(x, unicode) and isinstance(y, unicode): | |
normalized_x = ([c for c in unicodedata.normalize('NFKD', x) if not unicodedata.combining(c)] + [''])[0] | |
normalized_y = ([c for c in unicodedata.normalize('NFKD', y) if not unicodedata.combining(c)] + [''])[0] | |
return cmp(normalized_x, normalized_y) | |
return cmp(x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment