forked from colonelpanic/dotfiles
Add segment
This commit is contained in:
parent
7e6681fa53
commit
bf39a9bad6
13
dotfiles/lib/python/segment.py
Normal file
13
dotfiles/lib/python/segment.py
Normal 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
|
Loading…
Reference in New Issue
Block a user