mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +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)
|
"""itersplit(isSeparator, iterable, maxsplit=-1, yieldEmpty=False)
|
||||||
|
|
||||||
Splits an iterator based on a predicate isSeparator."""
|
Splits an iterator based on a predicate isSeparator."""
|
||||||
|
if isinstance(isSeparator, basestring):
|
||||||
|
f = lambda s: s == isSeparator
|
||||||
|
else:
|
||||||
|
f = isSeparator
|
||||||
acc = []
|
acc = []
|
||||||
for element in iterable:
|
for element in iterable:
|
||||||
if maxsplit == 0 or not isSeparator(element):
|
if maxsplit == 0 or not f(element):
|
||||||
acc.append(element)
|
acc.append(element)
|
||||||
else:
|
else:
|
||||||
maxsplit -= 1
|
maxsplit -= 1
|
||||||
|
Loading…
Reference in New Issue
Block a user