I've seen answers to this questions in SO, like here, and here. However, using the methods they suggested, the output I get in the file looks partly shifted.
Specifically, I've got a list of tuples, consisting of a number and a string. Using this solution, for example:
for t in sorted_words:
wrds.write(''.join(str(s) for s in t) + ' ')
What I get in the file is of the following format:
wordone
0.0 wordtwo
0.0 wordthree
0.0 wordfour
0.0
Any explanation for this? Thank you!