Created
November 16, 2013 09:37
-
-
Save shawwn/7498152 to your computer and use it in GitHub Desktop.
This file contains 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
import sys | |
import pdb | |
# iterate over 'blocksize' elems of a list at once. | |
def blocks(xs, blocksize): | |
for i in xrange(0, len(xs), blocksize): | |
yield xs[i:i+blocksize] | |
# partitions a list into groups of length blocksize. E.g.: | |
def blocklist(xs, blocksize): | |
return list(blocks(xs, blocksize)) | |
assert(blocklist([1, 2, 3, 4, 5, 6], 2) == [[1, 2], [3, 4], [5, 6]]) | |
assert(blocklist([1, 2, 3, 4, 5, 6], 3) == [[1, 2, 3], [4, 5, 6]]) | |
assert(blocklist([1, 2, 3, 4, 5, 6], 4) == [[1, 2, 3, 4], [5, 6]]) | |
def process(files): | |
fileslines = [] | |
for filename in files: | |
with open(filename, 'rb') as f: | |
fileslines.append(f.readlines()) | |
filesgroups = [blocklist(x, 5) for x in fileslines] | |
for groups in zip(*filesgroups): | |
for group in groups: | |
for line in group: | |
print line | |
process(sys.argv[1:]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment