mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-04-09 09:28:12 +02: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):
|
||||
for i in xrange(len(L) - (size-1)):
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user