Here I show a for loop which doesn't work well. What it prints is right while it only writes the last line to the .txt file. For example, it prints:
[0.173] [robe]
[0.493] [tree]
[0.274] [book]
But the file data01.txt has only one line:
[0.274] [book]
What I expect is the file includes all it prints.
for a_word in phrase_model.keys():
for b_word in phrase_model.keys():
a_val = phrase_model[a_word]
b_val = phrase_model[b_word]
c_word = [a_word, b_word]
cos_dis = cosine_similarity(a_val, b_val)
print(str(cos_dis) + str(c_word))
f = open('data01.txt', 'w')
f.write(str(cos_dis) + str(c_word))
f.close()