Forked from anonymous/gist:9897cd3c38490a7f68f4996f91367a86
Created
January 3, 2017 02:18
Revisions
-
There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #!/usr/bin/env python def split_into_groups(iterable, group_size): """Split an iterable collection into groups with fixed size. Yield ----- list[any] Groups of elements. """ buf = [] it = iter(iterable) try: while True: for i in range(group_size): buf.append(next(it)) yield buf del buf[:] except StopIteration: pass if buf: yield buf with open('input.txt', 'rb') as fin: for i, lines in enumerate(split_into_groups(fin, group_size=10000)): with open('output%d.txt' % i, 'wb') as fout: fout.write(b''.join(lines))