【发布时间】:2021-04-24 21:47:35
【问题描述】:
我有一个这样的列表:
mylist[1:3]=[{'Keywords': 'scrum master',
'result': {'categoryId': '3193',
'categoryName': 'agile coach',
'score': '1.0'},
'categoryId': '3193'},
{'Keywords': 'principal consultant',
'result': {'categoryId': '2655',
'categoryName': 'principal consultant',
'score': '1.045369052886963'},
'categoryId': '2655'},
{'Keywords': 'technicalfunctional consultant',
'result': []}]
我要运行以下代码:
categories=set(x['result']['categoryName'] for x in mylist)
它给了我错误:
TypeError: list indices must be integers or slices, not str
【问题讨论】:
标签: python list dictionary set