the.bay.news

Proposal: Add a `limit` parameter to `enumerate()`

Discussions on Python.org
Proposal: Add a `limit` parameter to `enumerate()`
I propose adding an optional limit parameter to the built-in enumerate() function to restrict the number of iterations. Limiting iteration is a common task, but current solutions are verbose: # Current approach: requires import and nesting from itertools import islice for i, item in islice(enumerate(data), 5): ... Alternatives have downsides: slicing creates copies, and zip(range(n), data) ignores the start parameter. Update the signature to: enumerate(iterable, start=0, limit=None) Ex...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.