我如何理解以下单行代码?
vins = {(vin['txid'], vin['vout']) for tx in raw_transactions
for vin in tx['vin'] if 'coinbase' not in vin}
更新1
我正在测试以下内容。
vins = []
for tx in raw_transactions:
for vin in tx['vin']:
if 'coinbase' not in vin:
vins.append(vin['txid'], vin['vout'])
更新2
这是raw_transactions。
[
{
'txid':'6a31558eadfd4d71316d1f074794716a660d3ca431ac0fa939daf4a971c3edde',
'vin':[
{
'vout':1,
'txid':'3579a3219c071afccddc0f2ac725ad844f5f16f25b253109df6996e824ef9c59'
}
],
'vout':[
{
'value':0.02159592,
'n':0
},
{
'value':0.007462,
'n':1
}
]
},
{
'txid':'92719026074f1e4ff3ea51b49da1a60b31ddda82456b24d70590276a5465687d',
'vin':[
{
'vout':0,
'txid':'6a31558eadfd4d71316d1f074794716a660d3ca431ac0fa939daf4a971c3edde',
}
],
'vout':[
{
'value':0.00226,
'n':0
},
{
'value':0.01481592,
'n':1
}
]
}
]
答案 0 :(得分:1)
它正在构建set
tuple
个值。这是一个非单行版本:
vins = set()
for tx in raw_transactions:
for vin in tx['vin']:
if 'coinbase' not in vin:
vins.add((vin['txid'], vin['vout']))