1# Answer written by Eswara Moorthy and edited by Igor Chubin and
2# Saurabh Bhandari on StackOverflow.com
3# (https://stackoverflow.com/revisions/44433664/4).
4# Licenced under CC BY-SA 4.0
5# (https://creativecommons.org/licenses/by-sa/4.0/).
6import unicodedata
7
8def strip_accents(text):
9
10 try:
11 text = unicode(text, 'utf-8')
12 except NameError: # unicode is a default on python 3
13 pass
14
15 text = unicodedata.normalize('NFD', text)\
16 .encode('ascii', 'ignore')\
17 .decode("utf-8")
18 return str(text)
19
20
21s = strip_accents('àéêöhello')
22
23print s
1def simplify(text):
2 import unicodedata
3 try:
4 text = unicode(text, 'utf-8')
5 except NameError:
6 pass
7 text = unicodedata.normalize('NFD', text).encode('ascii', 'ignore').decode("utf-8")
8 return str(text)