How to implement Unicode string matching by folding in python

后端 未结 5 959
灰色年华
灰色年华 2020-12-13 11:31

I have an application implementing incremental search. I have a catalog of unicode strings to be matched and match them to a given \"key\" string; a catalog string is a \"hi

5条回答
  •  情话喂你
    2020-12-13 12:12

    You can use this strip_accents function to remove the accents:

    def strip_accents(s):
       return ''.join((c for c in unicodedata.normalize('NFD', unicode(s)) if unicodedata.category(c) != 'Mn'))
    
    >>> strip_accents(u'Östblocket')
    'Ostblocket'
    

提交回复
热议问题