为什么我得到“列表"对象没有属性“项目"? [英] Why I get 'list' object has no attribute 'items'?

查看:67
本文介绍了为什么我得到“列表"对象没有属性“项目"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using Python 2.7, I have this list:

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

我想从中提取值.

[15, 9, 16]

所以我尝试了:

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

但相反,我收到此错误:

But instead, I get this error:

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

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

I'm wondering why this happens and how to fix it?

推荐答案

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

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

qs is a list, qs[0] is the dict which you want!

这篇关于为什么我得到“列表"对象没有属性“项目"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆