【发布时间】:2019-02-20 18:00:35
【问题描述】:
假设我的文件是这样的:
['720',
'717',
'"Diagnostic"',
'487',
'"{""status"": ""active""',
'""division_type"": ""Organisation""}"']
我需要选择 487 作为新字典中的键,并且 487 之后的单词保持原样。基本上是新字典中的字典。我已经尝试了以下代码:
for row in line:
key = row[3]
if key in d:
pass
d[key]=row[21:]
print(d)
我选择 3 是因为 487 是第三个索引,我选择 21 是因为在 csv 文件中,以下行位于第 21 行中。
我是编程新手。请帮帮我。 消息中的错误是:index is out of range
【问题讨论】:
-
我无法共享数据。不,它不是 JSON 字符串。
标签: python dictionary key