我有一个很大的json文件,其中包含关于ip地址传输信息的信息。网络地址中的一个或多个块可以传输到另一个实体。我想进一步映射到参与转移的单个实体it。你知道吗
Transfers =[{
"original_block": "87.118.128.0/18",
"transferred_blocks": "87.118.144.0/22, 87.118.164.0/22",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}, {
"original_block": "89.25.0.0/17",
"transferred_blocks": "89.25.40.0/21, 89.25.52.0/22,
89.25.56.0/21, 89.25.100.0/22, 89.25.124.0/22",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}, {
"original_block": "94.155.0.0/17",
"transferred_blocks": "94.155.104.0/21",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}]
with open ('Transfers','r') as t_list:#loads the json file
dlist = json.load(t_list)
for k, v in dlist:
dlist[k] = v("transferred_blocks").split(",")
预期输出如下:
dlist =[{
"original_block": "87.118.128.0/18",
"transferred_blocks": "87.118.164.0/22",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
},{
"original_block": "87.118.128.0/18",
"transferred_blocks": "87.118.144.0/22",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}, {
"original_block": "89.25.0.0/17",
"transferred_blocks": "89.25.40.0/21",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}, {
"original_block": "89.25.0.0/17",
"transferred_blocks": "89.25.52.0/22",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}, {
"original_block": "89.25.0.0/17",
"transferred_blocks": "89.25.56.0/21",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}, {
"original_block": "89.25.0.0/17",
"transferred_blocks": "89.25.100.0/22",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}, {
"original_block": "89.25.0.0/17",
"transferred_blocks": "89.25.124.0/22",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}, {
"original_block": "94.155.0.0/17",
"transferred_blocks": "94.155.104.0/21",
"from": "ITD Network SA",
"to": "Bulgarian Telecommunications Company Plc.",
"date": "16/07/2014",
"transferType": "POLICY"
}]
只需使用列表理解来迭代dlist中的每个dict,然后基于
comma
将ip地址列表拆分到transferred_blocks
下,最后使用更新的ip addr从原始dict创建一个新dict输出
相关问题 更多 >
编程相关推荐