Skip to content

Instantly share code, notes, and snippets.

@mitchellrj
Created May 26, 2012 09:08
Show Gist options
  • Save mitchellrj/2793033 to your computer and use it in GitHub Desktop.
Save mitchellrj/2793033 to your computer and use it in GitHub Desktop.
Normalized cmp for sorting lists of strings with accents
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