Skip to content

Instantly share code, notes, and snippets.

@mdrcode
Created June 5, 2013 17:42
Show Gist options
  • Save mdrcode/5715741 to your computer and use it in GitHub Desktop.
Save mdrcode/5715741 to your computer and use it in GitHub Desktop.
import sys
from itertools import islice
def window(seq, n=2):
"Returns a sliding window (of width n) over data from the iterable"
" s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ... "
it = iter(seq)
result = tuple(islice(it, n))
if len(result) == n:
yield result
for elem in it:
result = result[1:] + (elem,)
yield result
f = open(sys.argv[1], 'r')
lines = f.readlines()
for (i, (prev2, prev1, line)) in enumerate(window(lines, 3)):
if len(line) > (100 * 1000):
print "PREV2: %s" % prev2.strip()
print "PREV1: %s" % prev1.strip()
print "LINE: #: %d length: %d start: %s end: %s" % \
(i, len(line), line[22:100], line[-40:])
print ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment