python replace accented characters code

Solutions on MaxInterview for python replace accented characters code by the best coders in the world

showing results for - "python replace accented characters code"
Niclas
15 Jul 2017
1import unicodedata
2
3def strip_accents(text):
4
5    try:
6        text = unicode(text, 'utf-8')
7    except NameError: # unicode is a default on python 3 
8        pass
9
10    text = unicodedata.normalize('NFD', text)\
11           .encode('ascii', 'ignore')\
12           .decode("utf-8")
13
14    return str(text)
15
16s = strip_accents('àéêöhello')
17
18print s
19