小编Gur*_*der的帖子

如何在python 3中将字符串转换为字典

从字符串开始:

S='a=65 b=66 c=67'
Run Code Online (Sandbox Code Playgroud)

你会如何创建一个类似于dict的输出 {'a':'65','b':'66','c':'67'}

尝试:

S='a=65 b=66 c=67'
L=s.split(' ')
D=dict()
A=''
i=0
While i<Len(L):
    A=L[i].split('=')
    D[a[i]]=a[i+1]
    i+2

print (D)
Run Code Online (Sandbox Code Playgroud)

第8行indexerror列表索引超出范围时出错

python dictionary python-3.x

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

标签 统计

dictionary ×1

python ×1

python-3.x ×1