蟒蛇,从JSON元素的列表获取值的列表
问题描述:
我JSON元素的列表,看起来像这样(但更长时间)蟒蛇,从JSON元素的列表获取值的列表
[{u'account': u'', u'confirmations': 143236, u'amount': 5.61365738, u'address': u'8Zvt5usQB7dEEtyK7An3XFdqMSHgxTtZpz'}, {u'account': u'', u'confirmations': 2074, u'amount': 2.0, u'address': u'8K8GEVktJZQvrw5RtYzafD3qk3dAbNsTSQ'}]
我试着提取的所有'amount'
列表到一个列表花车,但我可以OLY得到一个单一的价值,这是我到目前为止的代码:
#!/usr/bin/env python
import json
import subprocess
json_data = json.loads(subprocess.check_output(['solarcoind', 'listreceivedbyaddress'], shell=False))
for a in json_data:
amounts = (a ['amount'])
print amounts
我打印只给出了最后一个值,在这种情况下2.0
,我如何列出所有金额吗?
答
amounts = [a['amount'] for a in json_data]
我想步骤1会......有一个列表? – jonrsharpe