Convert every dictionary value to utf-8 (dictionary comprehension?)

前端 未结 6 1843
旧巷少年郎
旧巷少年郎 2020-12-31 12:17

I have a dictionary and I want to convert every value to utf-8. This works, but is there a \"more pythonic\" way?

            for key in row.keys():
                


        
6条回答
  •  清歌不尽
    2020-12-31 12:35

    You can just iterate through the keys if you wanted to:

    {x:unicode(a[x]).encode("utf-8") for x in a.keys()}
    

提交回复
热议问题