Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将输出另存为networkx中的文本文件_Python_Networkx - Fatal编程技术网

Python 将输出另存为networkx中的文本文件

Python 将输出另存为networkx中的文本文件,python,networkx,Python,Networkx,我用python shell打印了一个输出,如: >>>{1: 117.33282674772036, 2: 119.55324074074075, 3: 116.45497076023392, 4: 113.77561475409836, 5: 112.93896713615024, 6: 114.23583333333333, 7: 124.92402972749794, 8: 121.40603448275863, 9: 116.494645247657

我用python shell打印了一个输出,如:

>>>{1: 117.33282674772036, 2: 119.55324074074075, 3: 116.45497076023392, 4:          113.77561475409836, 5: 112.93896713615024, 6: 114.23583333333333, 7: 124.92402972749794, 8: 121.40603448275863, 9: 116.4946452476573, 10: 112.89107142857142, 11: 122.33312577833125, 12: 116.57083333333334, 13: 122.2856334841629, 14: 125.26688815060908, 15: 129.13817204301074, 16: 128.78991596638656, 17: 127.54600301659126, 18: 133.65972222222223, 19: 127.28315789473685, 20: 125.07205882352942, 21: 124.79464285714286, 22: 131.36170212765958, 23: 130.17974002689377, 24: 138.37055555555557, 25: 132.72380952380954, 26: 138.44230769230768, 27: 134.82251082251082, 28: 147.12448979591838, 29: 149.86879730866275, 30: 145.04521072796936, 31: 143.72442396313363, 32: 148.12940140845072, 33: 140.06355218855219, 34: 145.44537815126051, 35: 146.50366300366301, 36: 146.2173611111111, 37: 152.36319881525361, 38: 156.42249459264599, 39: 154.6977564102564, 40: 155.47647058823529, 41: 158.72357723577235, 42: 162.23746031746032, 43: 149.30991931656382, 44: ........
它代表相邻的邻居。如何将此输出逐行保存在python中的文本文件中? 比如:

大概是这样的:

with open('some_file.txt', 'w') as f:
   for k in sorted(your_dic):
      f.write("{}:{}\n".format(k, your_dic[k]))
如何将此输出逐行保存在python中的文本文件中隐马尔可夫模型。。。只是在字典上迭代并写入文件?
with open('some_file.txt', 'w') as f:
   for k in sorted(your_dic):
      f.write("{}:{}\n".format(k, your_dic[k]))