从列表对象中获取特定值 - python

时间:2018-04-23 05:39:43

标签: python-3.x

我有像

这样的数据
sql = "select value, type from table"
cur.execute(sql)
row_headers = [x[0] for x in cur.description] #this will extract row headers
rv = cur.fetchall()
json_result = []
for result in rv:
    json_result.append(dict(zip(row_headers, result)))
finalresult = json.dumps(json_result)
#[{'value':30,'type':'SS'},{'value':40,'type':'KK'},{'value':80,'type':'SK'}]
attrList = list(map(lambda x: x['value'], finalresult))
return attrList

我想要OP:

[30,40,80]

但我收到了错误:

attrList = list(map(lambda x: x['value'], finalresult))
TypeError: string indices must be integers

我在哪里做错了?

0 个答案:

没有答案