From 57b2fffc0feb120df8e176c07276bf5a4272a604 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 25 Mar 2003 20:21:12 +0000 Subject: [PATCH] Added itersplit --- src/fix.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/fix.py b/src/fix.py index f83f7d136..f87c5998a 100644 --- a/src/fix.py +++ b/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: