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

前端 未结 6 1826
旧巷少年郎
旧巷少年郎 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:43

    Python 3 version building on that one answer by That1Guy.

    {k: str(v).encode("utf-8") for k,v in mydict.items()}
    

提交回复
热议问题