小编Sil*_*hen的帖子

将字典转换为字符串python

我正在尝试将字典转换为字符串

例如:

a={3:4,5:6}
s='3 4, 5 6'
Run Code Online (Sandbox Code Playgroud)

我正在尝试的方式是

s=''
i=0
for (k,v) in d.items():
    s=s+str(k)+' '+str(v)
    while i < len(s):
        if s[i]==str(v) and s[i+1]==str(k):
            s+=s+s[i]+','+s[i+1]
Run Code Online (Sandbox Code Playgroud)

python string dictionary

3
推荐指数
1
解决办法
77
查看次数

标签 统计

dictionary ×1

python ×1

string ×1