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 清单理解为一个清单的dict的dict?_Python_Dictionary_List Comprehension - Fatal编程技术网

Python 清单理解为一个清单的dict的dict?

Python 清单理解为一个清单的dict的dict?,python,dictionary,list-comprehension,Python,Dictionary,List Comprehension,我有一份字典的清单 下面是一个示例(JSON表单): 我将检索所有第二级dict值的列表,其中键为name。我已经试过了。但它不起作用 您知道如何在不编写多个for循环的情况下执行此操作吗。以下代码适合我: [d['name'] for lst in myJson for d in lst['stations']] myJson是我的dict of dict列表。[b['name']代表b在a['stations']代表a在jsonobj]?第一个想法是使用有效的JSON,只是说,“…是的,很

我有一份字典的清单

下面是一个示例(JSON表单):

我将检索所有第二级dict值的列表,其中键为
name
。我已经试过了。但它不起作用


您知道如何在不编写多个for循环的情况下执行此操作吗。

以下代码适合我:

[d['name'] for lst in myJson for d in lst['stations']]

myJson
是我的dict of dict列表。

[b['name']代表b在a['stations']代表a在jsonobj]
?第一个想法是使用有效的JSON,只是说,“…是的,很抱歉,我更新了它。@markcial根据你的想法,我得出了这个结论:
[d['name']代表我的JSON中的lst代表d,代表lst['stations']
谢谢。
[d['name'] for lst in myJson for d in lst['stations']]