0

This question is a followed up on this question

I've posted the solution by @tobiask here as well:

match_region = [map(str, blob.sentences[i-1:i+2])     # from prev to after next
                for i, s in enumerate(blob.sentences) # i is index, e is element
                if search_words & set(s.words)]       # same as your condition

I am having trouble exporting the match_region file. I would like to turn this into a csv with the sentences as columns and every result as a row.

Community
  • 1
  • 1
Melvin Wevers
  • 151
  • 4
  • 11
  • Your indents are wrong in the code you posted. Also, maybe you could post a sample of what the output should look like. – Joseph James Apr 07 '16 at 22:11
  • I just copied the indents from the other posts. Shall look into them. – Melvin Wevers Apr 07 '16 at 22:20
  • output should have the sentence with the query words + the i-1 and i+2 in the other columns. Every row would contain a sentence with a words from the search_word list. – Melvin Wevers Apr 07 '16 at 22:21

1 Answers1

0

This will print the contents of the match_region to a file, but I didn't test it on your code, and it doesn't print the sentences.

with open('output.csv', 'w') as f:
    for i, s in enumerate(match_region):
        f.write('"' + i + '","' + s + '"\n')
Joseph James
  • 168
  • 1
  • 13