2012年12月30日

摘要: 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... 阅读全文
posted @ 2012-12-30 16:38 rongyilin 阅读(213) 评论(0) 推荐(0) 编辑
摘要: # -*- 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,... 阅读全文
posted @ 2012-12-30 16:05 rongyilin 阅读(484) 评论(0) 推荐(0) 编辑

导航