首页 > 解决方案 > 如何使用理解从 python 中的字典中创建值列表

问题描述

{'AAPL': (175.96, 'Apple Inc'),
 'GOOGL': (0.00475, 'Alphabet Inc'),
 'TVIX': (0.0045, 'Credit Suisse AG')}

如何提取以下列表:Apple In、、Alphabet IncCredit Suisse AG

标签: pythondictionarylist-comprehension

解决方案


使用此列表理解:

print([i[1] for i in yourdictionary.values()])

输出:

['Apple Inc', 'Alphabet Inc', 'Credit Suisse AG']

PS 更改yourdictionary为您的字典的实际名称。


推荐阅读