Skip to content

Instantly share code, notes, and snippets.

@acrymble
Created July 6, 2011 09:49
Show Gist options
  • Select an option

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

Select an option

Save acrymble/1066931 to your computer and use it in GitHub Desktop.
Python KWIC Pretty Printing
# Given a KWIC, return a string that is formatted for
# pretty printing.
def prettyPrintKWIC(kwic):
n = len(kwic)
keyindex = n // 2
width = 10
outstring = ' '.join(kwic[:keyindex]).rjust(width*keyindex)
outstring += str(kwic[keyindex]).center(len(kwic[keyindex])+6)
outstring += ' '.join(kwic[(keyindex+1):])
return outstring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment