Skip to content

Instantly share code, notes, and snippets.

@eHammarstrom
Created January 10, 2020 18:55
Show Gist options
  • Save eHammarstrom/ead3f42083e437e3f357ddcf67de6c9a to your computer and use it in GitHub Desktop.
Save eHammarstrom/ead3f42083e437e3f357ddcf67de6c9a to your computer and use it in GitHub Desktop.
import sys
if len(sys.argv) != 2:
exit(1)
text = open(sys.argv[1], 'r').read()
words = text.replace("\n", " ").split(" ")
for i in range(1, len(words)):
prev_word = words[i-1]
curr_word = words[i]
if prev_word == curr_word:
if curr_word in ['', ' ']: # skip some leftovers
continue
# print word and context
print('repeated word (', curr_word, ')', 'line: ', end='\n\t')
for j in range(5):
if (i-3+j) > 0:
print(words[i-3+j], end=' ')
print('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment