Add split_by_n function on utils.iterators module.
parent
6928c39281
commit
4aef603946
|
@ -33,3 +33,12 @@ def as_dict(function):
|
|||
def _decorator(*args, **kwargs):
|
||||
return dict(function(*args, **kwargs))
|
||||
return _decorator
|
||||
|
||||
|
||||
def split_by_n(seq:str, n:int):
|
||||
"""
|
||||
A generator to divide a sequence into chunks of n units.
|
||||
"""
|
||||
while seq:
|
||||
yield seq[:n]
|
||||
seq = seq[n:]
|
||||
|
|
Loading…
Reference in New Issue