Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Remove Accents by MarcAureleCoste
import unicodedata
def checkio(in_string):
"""Remove accents from the input string.
We use the the unicodata module to normilize the string. We want to remove
accents and not all the non ASCII charaters. To do that we will go through
our normalized string and get all the non combining characters.
Example:
>>> s = 'éàçù'
>>> bytes(s, 'utf-8') # return b'\xc3\xa9\xc3\xa0\xc3\xa7\xc3\xb9'
>>> bytes(unicodedata.normalize('NFKD'), s) # b'e\xcc\x81a\xcc\x80c\xcc\xa7u\xcc\x80'
"""
normalized_str = unicodedata.normalize('NFKD', in_string)
return ''.join([c for c in normalized_str if not unicodedata.combining(c)])
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(u"préfèrent") == u"preferent"
assert checkio(u"loài trăn lớn") == u"loai tran lon"
print('Done')
Feb. 3, 2021