mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
Allow isSeparator to be a function.
This commit is contained in:
parent
dffa1782d1
commit
11de062c20
@ -461,9 +461,13 @@ def itersplit(isSeparator, iterable, maxsplit=-1, yieldEmpty=False):
|
||||
"""itersplit(isSeparator, iterable, maxsplit=-1, yieldEmpty=False)
|
||||
|
||||
Splits an iterator based on a predicate isSeparator."""
|
||||
if isinstance(isSeparator, basestring):
|
||||
f = lambda s: s == isSeparator
|
||||
else:
|
||||
f = isSeparator
|
||||
acc = []
|
||||
for element in iterable:
|
||||
if maxsplit == 0 or not isSeparator(element):
|
||||
if maxsplit == 0 or not f(element):
|
||||
acc.append(element)
|
||||
else:
|
||||
maxsplit -= 1
|
||||
|
Loading…
Reference in New Issue
Block a user