mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added group and test for group.
This commit is contained in:
parent
eb6fb90801
commit
2760c1bce0
31
src/fix.py
31
src/fix.py
@ -233,21 +233,22 @@ def ilen(iterator):
|
||||
i += 1
|
||||
return i
|
||||
|
||||
## def group(seq, groupSize):
|
||||
## L = []
|
||||
## LL = []
|
||||
## i = groupSize
|
||||
## for elt in seq:
|
||||
## if i > 0:
|
||||
## LL.append(elt)
|
||||
## i -= 1
|
||||
## else:
|
||||
## L.append(LL)
|
||||
## i = groupSize
|
||||
## LL = []
|
||||
## if LL:
|
||||
## L.append(LL)
|
||||
## return L
|
||||
def group(seq, groupSize):
|
||||
ret = []
|
||||
L = []
|
||||
i = groupSize
|
||||
for elt in seq:
|
||||
if i > 0:
|
||||
L.append(elt)
|
||||
else:
|
||||
ret.append(L)
|
||||
i = groupSize
|
||||
L = []
|
||||
L.append(elt)
|
||||
i -= 1
|
||||
if L:
|
||||
ret.append(L)
|
||||
return ret
|
||||
|
||||
def itersplit(iterable, isSeparator, yieldEmpty=False):
|
||||
acc = []
|
||||
|
@ -49,6 +49,13 @@ class FunctionsTest(unittest.TestCase):
|
||||
for elt in reviter([]):
|
||||
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):
|
||||
L = range(10)
|
||||
def wwindow(*args):
|
||||
|
Loading…
Reference in New Issue
Block a user