Allow isSeparator to be a function.

This commit is contained in:
Jeremy Fincher 2004-10-26 21:09:20 +00:00
parent dffa1782d1
commit 11de062c20

View File

@ -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