python - TypeError: must be str, not list -


the problem output result not save in csv file. i'm using code weight-age words positive , negative.i want save in csv file.firstly, read csv file ,apply tf-idf , output display on shell,but error disply when result write in csv file.

for i, blob in enumerate(bloblist):     print("top words in document {}".format(i + 1))     scores = {word: tfidf(word, blob, bloblist) word in blob.words}     sorted_words = sorted(scores.items(), reverse=true)     print(sorted_words)     final = open("tfidf.csv", "w").write(sorted_words)     print(final)     print("done") 

the error is:

   top words in document 1    traceback (most recent call last):    file "c:\python34\webcrawler-final.py", line 38, in <module>    final = open("tfidf.csv", "w").write(sorted_words)    typeerror: must str, not list 

try this.

sorted_words = ''.join(sorted(scores.items(), reverse=true)) 

Comments