从列表中提取所需元素并制作另一个lis

2024-07-05 11:54:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的列表,我只想从中提取姓名,然后再列出另一个列表。有人能帮我做到这一点吗

>>> a = [{'name': 'mytestbuild', 'notes': 'Autocreated build.', 'testplan_id': '178775', 'closed_on_date': '', 'release_date': '', 'is_open': '1', 'active': '1', 'creation_ts': '2017-05-09 11:20:25', 'id': '160'}, {'name': 'mytestbuild_delete', 'notes': 'Autocreated build.', 'testplan_id': '178775', 'closed_on_date': '', 'release_date': '', 'is_open': '1', 'active': '1', 'creation_ts': '2017-05-18 15:24:37', 'id': '164'}]

从中,我只想得到“名称”列表,即

name_list = ['mytestbuild', 'mytestbuild_delete']

这不起作用:

>>> a['name']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not str

Tags: namebuildid列表datereleaseison