1000 , ; , - N , ( , N , N 32, 1000 ). " N " ( , ).
, ( heapq ;-) , " " ( TLD ), , , , ( - , , , ). , - , , , ( , , ;-).
import heapq
def merge(inputfiles, outputfile, key):
"""inputfiles: list of input, sorted files open for reading.
outputfile: output file open for writing.
key: callable supplying the "key" to use for each line.
"""
h = [(k, i.readline(), i) for k, i in enumerate(inputfiles)]
h = [[key(s), k, s, i] for k, s, i in h if s]
heapq.heapify(h)
while h:
item = heapq.heappop(h)
outputfile.write(item[2])
item[2] = item[3].readline()
if not item[2]: continue
item[0] = key(item[2])
heapq.heappush(h, item)
, , key, , , , ( ) - urlparse . ,
def tld(domain):
return domain.rsplit('.', 1)[-1].strip()
- , , .
Python 2.6 , heapq.merge , ( , " " ...) "/undecorate", .