mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00
15 lines
361 B
Python
15 lines
361 B
Python
![]() |
from itertools import islice
|
||
|
|
||
|
try:
|
||
|
# batched is in 3.12
|
||
|
from itertools import batched
|
||
|
except ImportError:
|
||
|
|
||
|
def batched(iterable, n):
|
||
|
# batched('ABCDEFG', 3) --> ABC DEF G
|
||
|
if n < 1:
|
||
|
raise ValueError('n must be at least one')
|
||
|
it = iter(iterable)
|
||
|
while batch := tuple(islice(it, n)):
|
||
|
yield batch
|