Skip to content

Instantly share code, notes, and snippets.

@Peilonrayz Peilonrayz/something.py Secret
Last active Nov 21, 2017

Embed
What would you like to do?
Example alturnate solution to https://codereview.stackexchange.com/q/180920
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):
try:
print(n, [list(v) for k, v in groupby(data, sublist_size(n))])
except ValueError as e:
print(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.