您好,我想将词典列表转换为列表中某些项的单个词典: 我有:
>>> print(dct_lst)
[{'id': 456, 'name': 'bar'}, {'id': 789, 'name': 'baz'}, {'id': 123, 'name': 'foo'}]
我想:
dct={'bar':None
'baz':None
'foof':None}
我尝试过(在其他组合中):
>>> for i in dct_lst['name']:
... btns[i]=None
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not str
我怎样才能得到我需要的
考虑使用<强>dict comprehension>:
相关问题 更多 >
编程相关推荐