Added group and test for group.

This commit is contained in:
Jeremy Fincher 2003-08-11 07:12:41 +00:00
parent eb6fb90801
commit 2760c1bce0
2 changed files with 23 additions and 15 deletions

View File

@ -233,21 +233,22 @@ def ilen(iterator):
i += 1 i += 1
return i return i
## def group(seq, groupSize): def group(seq, groupSize):
## L = [] ret = []
## LL = [] L = []
## i = groupSize i = groupSize
## for elt in seq: for elt in seq:
## if i > 0: if i > 0:
## LL.append(elt) L.append(elt)
## i -= 1 else:
## else: ret.append(L)
## L.append(LL) i = groupSize
## i = groupSize L = []
## LL = [] L.append(elt)
## if LL: i -= 1
## L.append(LL) if L:
## return L ret.append(L)
return ret
def itersplit(iterable, isSeparator, yieldEmpty=False): def itersplit(iterable, isSeparator, yieldEmpty=False):
acc = [] acc = []

View File

@ -49,6 +49,13 @@ class FunctionsTest(unittest.TestCase):
for elt in reviter([]): for elt in reviter([]):
self.fail('reviter caused iteration over empty sequence') self.fail('reviter caused iteration over empty sequence')
def testGroup(self):
s = '1. d4 d5 2. Nf3 Nc6 3. e3 Nf6 4. Nc3 e6 5. Bd3 a6'
self.assertEqual(group(s.split(), 3)[:3],
[['1.', 'd4', 'd5'],
['2.', 'Nf3', 'Nc6'],
['3.', 'e3', 'Nf6']])
def testWindow(self): def testWindow(self):
L = range(10) L = range(10)
def wwindow(*args): def wwindow(*args):