python - 为什么我得到 'list' object has no attribute 'items' ?

标签 python python-2.7

使用 Python 2.7,我有这个列表:

qs = [{u'a': 15L, u'b': 9L, u'a': 16L}]

我想从中提取值(value)。

[15, 9, 16]

所以我尝试了:

result_list = [int(v) for k,v in qs.items()]

但是,我得到了这个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'items'

我想知道为什么会发生这种情况以及如何解决它?

最佳答案

result_list = [int(v) for k,v in qs[0].items()]

qs 是一个列表,qs[0] 是你想要的字典!

关于python - 为什么我得到 'list' object has no attribute 'items' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33949856/

相关文章:

python - Scrapy - 我在哪里可以在 Linux Ubuntu E4.5 上找到它

Python 2.7 异常处理语法

python - 将大型二进制文件转换为十六进制(binascii.hexlify 返回 MemoryError)

python - 当 Eclipse PyUnit Test Runner 配置为使用 Nose 时,控制台输出去哪里

python - 上传 python 包而不重建

python - 如何计算字典列表中特定字典键的出现次数

python - 随机选择一个元组集,然后将其从原始元组列表中删除

python - 在 python 中读取文本文件(Powershell 脚本的输出)会产生意外结果?

python - 导入错误 : No module named pyplot (even after installing matplotlib)

Python 2.7 字符串格式