--- warning: This file is auto generated by `yarn web:inject`, do not edit by hand examples: - batched([1, 2, 3, 4, 5], 2) returns: - '[[1, 2], [3, 4], [5]]' dependencies: - python/_helpers/_itertools authors: original by: - Kevin van Zonneveld (https://kvz.io) notes: [] parityVerified: - Python 3.12 isTypescript: true type: function layout: function title: Python's itertools.batched in TypeScript description: >- Here's what our current TypeScript equivalent to Python's itertools.batched looks like. function: batched category: itertools language: python permalink: python/itertools/batched/ alias: - /functions/python/batched/ - /functions/itertools/batched/ - /python/batched/ ---
{% codeblock lang:typescript %}import { itertoolsBatched } from '../_helpers/_itertools.ts' export function batched(iterable: unknown, n: unknown): unknown[][] { // discuss at: https://locutus.io/python/itertools/batched/ // parity verified: Python 3.12 // original by: Kevin van Zonneveld (https://kvz.io) // example 1: batched([1, 2, 3, 4, 5], 2) // returns 1: [[1, 2], [3, 4], [5]] return itertoolsBatched(iterable, n) } {% endcodeblock %}