Created
May 27, 2014 04:57
-
-
Save luistung/4b977c17d2d568a469fa to your computer and use it in GitHub Desktop.
多路归并
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
import os | |
import sys | |
import heapq | |
fileList = [open(sys.argv[1] + '/' + f) for f in os.listdir(sys.argv[1])] | |
def lineIterator(f): | |
for line in f: | |
line = line.rstrip() | |
tokens = line.split('\t') | |
if len(tokens) <> 3:continue | |
key = (tokens[0], tokens[1]) | |
yield (key, line) | |
for line in heapq.merge(*map(lineIterator, fileList)): | |
print line[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment