Created
August 30, 2014 15:05
-
-
Save rcalsaverini/30bb8212809d29592222 to your computer and use it in GitHub Desktop.
Removing accents from unicode strings in python
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 strip_accents(unicode_string): | |
""" | |
Strip accents (all combining unicode characters) from a unicode string. | |
""" | |
ndf_string = unicodedata.normalize('NFD', unicode_string) | |
is_not_accent = lambda char: unicodedata.category(char) != 'Mn' | |
return ''.join( | |
char for char in ndf_string if is_not_accent(char) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment