从Python的字典列表中切片一个字典值



我正在尝试将我的List of Dictionary中的特定值附加到另一个List中。

All_Result={'Team Name':[]}

试图添加

all_result['SupportGroup'].append(issue["fields"]["Team Name"]['objectId'])

这就得到了

TypeError:列表索引必须是整数或切片,而不是str

如何从下面的字典列表中获取objectId并将其附加到All_Result中?

这是我的字典列表

"Team Name" = [{
'workspaceId': 'fdxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'id': 'fdxxxxxxxxxxxxxxxxxx',
'objectId': '1234'
}]

请帮助

在您的问题["fields"]字典中,键'Team Name'的值看起来不是字典本身,而是字典列表。因此,您需要使用索引来访问包含'objectId'键的列表中的字典。

假设issue["fields"]["Team Name"]是字典列表,您可以访问列表中的第一个字典(根据您的示例,它应该是唯一的一个),然后使用键获取'objectId'值。下面是一个如何修改代码的示例,将'objectId'值附加到All_Result['Team Name']:

All_Result = {'Team Name': []}
# Assuming issue["fields"]["Team Name"] is a list of dictionaries
team_dict = issue["fields"]["Team Name"][0]
All_Result['Team Name'].append(team_dict['objectId'])

最新更新