Skip to content

Instantly share code, notes, and snippets.

@acrymble
Created July 5, 2011 20:00
Show Gist options
  • Select an option

  • Save acrymble/1065766 to your computer and use it in GitHub Desktop.

Select an option

Save acrymble/1065766 to your computer and use it in GitHub Desktop.
Python KWIC
wordstring = 'it was the best of times it was the worst of times '
wordstring += 'it was the age of wisdom it was the age of foolishness'
wordlist = wordstring.split()
print wordlist[0:4]
-> ['it', 'was', 'the', 'best']
print wordlist[0:6]
-> ['it', 'was', 'the', 'best', 'of', 'times']
print wordlist[6:10]
-> ['it', 'was', 'the', 'worst']
print wordlist[0:12]
-> ['it', 'was', 'the', 'best', 'of', 'times', 'it', 'was', 'the', 'worst', 'of', 'times']
print wordlist[:12]
-> ['it', 'was', 'the', 'best', 'of', 'times', 'it', 'was', 'the', 'worst', 'of', 'times']
print wordlist[12:]
-> ['it', 'was', 'the', 'age', 'of', 'wisdom', 'it', 'was', 'the', 'age', 'of', 'foolishness']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment