Add segment

This commit is contained in:
Ivan Malison 2016-01-11 16:23:52 -08:00
parent 7e6681fa53
commit bf39a9bad6

View File

@ -0,0 +1,13 @@
def segment(iterable, segment_length):
if segment_length is None:
yield iterable
raise StopIteration
def yield_length():
for _ in xrange(segment_length):
yield iterable.next()
while True:
segment = list(yield_length())
if not segment:
raise StopIteration
yield segment