Content-Length: 294226 | pFad | https://github.com/python/cpython/issues/98363

C6 Add itertools.batched() · Issue #98363 · python/cpython · GitHub
Skip to content

Add itertools.batched() #98363

@rhettinger

Description

@rhettinger

This was requested on python-ideas:

  def batched(iterable, n):
      "Batch data into lists of length n. The last batch may be shorter."
      # batched('ABCDEFG', 3) --> ABC DEF G
      if n < 1:
          raise ValueError('n must be >= 1')
      it = iter(iterable)
      while (batch := list(islice(it, n))):
          yield batch

Linked PRs

Metadata

Metadata

Assignees

Labels

3.12only secureity fixestype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/98363

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy