python 判断两个字典相同的元素后刪除字典中特定的值[{},{},{}]

from pprint import pprint
from copy import deepcopy

tx1 = {"_id":"a82bcbade7f2ab98a0b9208dae2e5fa6b44f5e37f8403ec8f74ca63c4d6189d2",
    "blocknumber":80002,
    "blocktime":1284615935,
    "vin":[{"id":"11","value":50.0,"address":["1LgsbKRKTcw7gYohUwntSUh6rtEWShxSH8"]},
    {"id":"232","value":530.0,"address":["qwe234"]},
     {"id":"22","value":50.0,"address":["qwerty123"]},
     {"id":"22","value":50.0,"address":["qwerty12323455"]},
    ],
    "vout":[{"id":"0","value":50.0,"address":["1LgsbKRKTcw7gYohUwntSUh6rtEWShxSH8"]},
    {"id":"22","value":50.0,"address":["qwe123"]},
    {"id":"232","value":530.0,"address":["zuuEcUSsBjL7s"]},
    {"id":"232","value":530.0,"address":["eeeeeeee"]},
    {"id":"232","value":530.0,"address":["qwerty12323455"]}
    ]}



# pprint(tx)


def get_outputList(tx):
    vout=tx["vout"]  # list
    vin=tx["vin"]    # list
    for vi in vin:
        
        if vi['id'] == 'coinbase':
            for vout_data in vout:
                if vout_data["address"] != "":
                    dic={
                        "address": vout_data["address"][0],
                        "value": vout_data["value"]
                    }
                    # outputList.append(dic)
                    pprint(dic)
                    return dic
        else:
            # 判断vin中的地址是否在vout中出现,若出现在vout中,则删除掉vout中的这笔交易
            vout1 =deepcopy(vout)
            for vi in vin:
                for vo in vout1:
                    if vi["address"] == vo["address"]:
                        vout1.remove(vo)

            outputList=[]
            for vo1 in vout1:
                output = {
                "address":vo1["address"][0],
                "value":vo1["value"]
                }
                outputList.append(output)




    pprint(outputList)
    return outputList
            # outputList.append(vout)
    # pprint(outputList)


if __name__ == '__main__':
    tx = {'_id': '0ca067b886f20efcf9c4cdaa4317f68bb39e0d3adf04eba5ddc025a8ef35119d',
         'blocknumber': 77913,
         'blocktime': 1283548095,
         'vin': [{'address': [''], 'id': 'coinbase', 'value': 0.0}],
         'vout': [{'address': ['1BwaFhJVVAwzv7zWyfyxfW9QKBdmruYUB4'],
                   'id': '0',
                   'value': 50.0}]}



    get_outputList(tx1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值