Py学习  »  Python

将python字典组合成字符串csv

Evan Graves • 5 年前 • 1666 次点击  

我这里有本字典:

dict = {'AB': 1, 'AE': '0', 'CC': '3'}

我正试着把字典转换成字符串格式:

AB1,AE0,CC3

我目前正在尝试:

string = ",".join(("{},{}".format(*i) for i in dict.items()))

但我的成果是:

AB,1,AE,0,CC,3

只是稍微差了一点。

有人知道如何将这本字典正确地格式化成字符串吗?

谢谢

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44297
 
1666 次点击  
文章 [ 5 ]  |  最新文章 5 年前