[关闭]
@EggGump 2018-09-13T21:26:43.000000Z 字数 433 阅读 388

pickle简单使用

python


  1. import pickle
  2. from operator import itemgetter
  3. data = {(1,2,3):[[1,3],[2,1],[3,0.4]],(4,5,6):[[1,3],[2,4],[3,6]]}
  4. # with open('tmp.pk','wb') as f:
  5. # pickle.dump(data,f)
  6. data = 0
  7. with open('tmp.pk','rb') as f:
  8. data = pickle.load(f)
  9. item = data.items()
  10. for i in item:
  11. triple = i[0]
  12. entityScore = i[1]
  13. sortresult = entityScore
  14. print(triple)
  15. print(sortresult)
  16. for index in range(len(sortresult)):
  17. tail = sortresult[index][0]
  18. if tail == triple[1]:
  19. print(index,sortresult[index])
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注