I need to store the print value of this code into a variable so that I can dump it into a text file.
for i, j, v in sorted(zip(m.row, m.col, m.data)):
if doc_id == -1:
print(str(j) + ':' + "{:.4f}".format(v), end=' ')
else:
if doc_id != i:
print()
print(str(j) + ':' + "{:.4f}".format(v), end=' ')
doc_id = i
I used list comprehension and appending it into a variable but didn't help.