摘要:
1 ## {{{ http://code.activestate.com/recipes/577361/ (r1) 2 import collections 3 class peekable(object): 4 """ An iterator that supports a peek operation. 5 6 this is a merge of example 19.18 of python cookbook part 2, peek ahead more steps 7 and the simpler example 16.7, w... 阅读全文
摘要:
# -*- coding: utf-8 -*-def merge(*sequences): import heapq heap = [(seq[0],seq) for seq in sequences] heapq.heapify(heap) while heap: x, seq = heapq.heappop(heap) yield seq.pop(0) if seq: heapq.heappush(heap, (seq[0], seq))A = [[1,2,3,4], [5,6,8], [1,3,5,... 阅读全文