- 815 名前:デフォルトの名無しさん mailto:sage [2008/12/27(土) 10:03:05 ]
- from 俺のitertools import pair
def pair(iterable, count): """ >>> list(pair(range(10), 3)) [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9,)] """ iterable = iter(iterable) stop = False while not stop: y = () try: for i in range(count): y += (iterable.next(), ) except StopIteration: stop = True if y: yield y
|

|