Skip to content

Instantly share code, notes, and snippets.

@Peilonrayz Peilonrayz/ Secret
Last active Nov 21, 2017

What would you like to do?
Example alturnate solution to
from itertools import groupby
def sublist_size(max_size):
cur_size = 0
id_ = 0
def inner(n):
nonlocal cur_size, id_
if len(n) > max_size:
raise ValueError(f'Use a bigger size than {max_size}')
cur_size += len(n)
if cur_size > max_size:
cur_size = len(n)
id_ += 1
return id_
return inner
data = ["1", "22", "333", "4444", "55555", "666666", "7777777", "88888888"]
for n in range(17):
print(n, [list(v) for k, v in groupby(data, sublist_size(n))])
except ValueError as e:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.