Created
July 6, 2011 09:24
-
-
Save acrymble/1066901 to your computer and use it in GitHub Desktop.
Python slice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # calculate the length of the n-gram | |
| kwic = 'amongst them a black there was one'.split() | |
| n = len(kwic) | |
| print n | |
| -> 7 | |
| # calculate the index position of the keyword | |
| keyindex = n // 2 | |
| print keyindex | |
| -> 3 | |
| # display the items before the keyword | |
| print kwic[:keyindex] | |
| -> ['amongst', 'them', 'a'] | |
| # display the keyword only | |
| print kwic[keyindex] | |
| -> black | |
| # display the items after the keyword | |
| print kwic[(keyindex+1):] | |
| -> ['there', 'was', 'one'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment