mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-03-01 12:00:41 +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
|
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 = []
|
||||||
|
@ -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):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user