mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-17 15:13:02 +01:00
Added itersplit
This commit is contained in:
parent
d3e28c1cfe
commit
57b2fffc0f
13
src/fix.py
13
src/fix.py
@ -201,4 +201,17 @@ def enumerate(L):
|
|||||||
def window(L, size):
|
def window(L, size):
|
||||||
for i in xrange(len(L) - (size-1)):
|
for i in xrange(len(L) - (size-1)):
|
||||||
yield L[i:i+size]
|
yield L[i:i+size]
|
||||||
|
|
||||||
|
def itersplit(iterable, isSeparator, yieldEmpty=False):
|
||||||
|
acc = []
|
||||||
|
for element in iterable:
|
||||||
|
if isSeparator(element):
|
||||||
|
if yieldEmpty or acc:
|
||||||
|
yield acc
|
||||||
|
acc = []
|
||||||
|
else:
|
||||||
|
acc.append(element)
|
||||||
|
if yieldEmpty or acc:
|
||||||
|
yield acc
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user