用python提取链序列

时间:2011-12-26 13:55:52

标签: python

我在Python中有一个字典,它描述了在各种主机上运行的某些类型的二进制文件。其中一些是彼此连接的。问题是 - 我怎样才能从中构建链?如果输入和输出相同,则连接二进制文件。 例如:

{"binary1": "bin1", "input": "127.0.0.1:2222", "output": "127.0.0.2:3333", "other_stuff": "....1111..."}
{"binary2": "bin2", "input": "127.0.0.2:3333", "output": "", "other_stuff": "....2222..."}
{"binary3": "bin3", "input": "128.0.0.1:5555", "output": "127.0.0.2:7777", "other_stuff": "....3333..."}
{"binary4": "bin4", "input": "127.0.0.2:8888", "output": "127.0.0.2:4444", "other_stuff": "....4444..."}
{"binary5": "bin5", "input": "127.0.0.1:9999", "output": "127.0.0.2:8888", "other_stuff": "....5555..."}
{"binary6": "bin6", "input": "127.0.0.5:1111", "output": "127.0.0.9:1234", "other_stuff": "....6666..."}
{"binary7": "bin7", "input": "", "output": "127.0.0.1:9999", "other_stuff": "....7777..."}
{"binary8": "bin8", "input": "127.0.0.1:2222", "output": "127.0.0.2:3333", "other_stuff": "....8888..."}
{"binary9": "bin9", "input": "", "output": "127.0.0.5:1111", "other_stuff": "....9999..."}
{"binary0": "bin0", "input": "", "output": "", "other_stuff": "....0000..."}

预期产出:

bin1 -> bin2
bin7 -> bin5 -> bin4
bin9 -> bin6

每个二进制文件不需要输入和输出 最后,我需要制作链列表并绘制它们,但这是一个奖励:)是否存在一些python模块,它将有助于提取序列并快速完成它? (数据大小约为10万个二进制文件) 提前谢谢!
附:实际上我需要链接到python模块,这将帮助我解决它(不是算法),这都是

1 个答案:

答案 0 :(得分:3)

编写自定义代码来执行您所要求的操作非常简单,但既然您指定了“指向python模块的链接”,那么我的建议是查看python-graphs。从它的外观来看,你的问题似乎等同于构建有向图...

编辑:这也回答了关于绘制绘图的奖金问题。请参阅this示例。