Easiest way to remove unicode representations from a string in python 3?

前端 未结 3 717
无人共我
无人共我 2021-01-12 05:26

I have a string in python 3 that has several unicode representations in it, for example:

t = \'R\\\\u00f3is\\\\u00edn\'

and I want to conve

3条回答
  •  清酒与你
    2021-01-12 06:06

    First of all, it is rather confused what you what to convert to.

    Just imagine that you may want to convert to 'o' and 'i'. In this case you can just make a map:

    mp = {u'\u00f3':'o', u'\u00ed':'i'}
    

    Than you may apply the replacement like:

    t = u'R\u00f3is\u00edn'
    for i in range(len(t)):
        if t[i] in mp: t[i]=mp[t[i]]
    print t
    

提交回复
热议问题