mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-15 15:09:23 +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):
|
||||
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…
Reference in New Issue
Block a user