Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何仅提取列表中每个元素的一部分?_Python_List - Fatal编程技术网

Python 如何仅提取列表中每个元素的一部分?

Python 如何仅提取列表中每个元素的一部分?,python,list,Python,List,我想从列表中提取idid是自动生成的 BOOKS[ { 'id':'12345edfer8498erf84f8', 'name':'Mr.k' } ] 如何仅选择id print(BOOKS['id']) 它不起作用 我想要的示例: print(BOOKS['id']) 输出: id:12345edfer8498erf84f8 它位于索引0。因此,访问它就像: 书籍[0]['id']使用书籍[0]['id']: books = [ { 'id': '12

我想从列表中提取
id
<代码>id是自动生成的

BOOKS[
  {
    'id':'12345edfer8498erf84f8',
    'name':'Mr.k'
  }
]
如何仅选择
id

print(BOOKS['id'])
它不起作用

我想要的示例:

print(BOOKS['id'])
输出:

id:12345edfer8498erf84f8

它位于索引
0
。因此,访问它就像:


书籍[0]['id']
使用
书籍[0]['id']

books = [
  {
    'id': '12345edfer8498erf84f8',
    'name': 'Mr.k'
  }
]

print(books[0]['id']) # output 12345edfer8498erf84f8

书籍
是一个列表。您应该访问其中的第一个元素:
BOOKS[0]['id']
BOOKS[0]['id']