Question: Say I have a list of items, and I want to iterate over the first few of it:

```
items = list(range(10)) # I mean this to represent any kind of iterable.
limit = 5

```

Naive implementation
--------------------

The Python naïf coming from other languages would probably write this perfectly serviceable and performant (if unidiomatic) code:

```
index = 0
for item in items: # Python's `for` loop is a for-each.
    print(item)    # or whatever function of that item.
    index += 1
    if index == limit:
        break

```

More idiomatic implementation
-----------------------------

But Python has enumerate, which subsumes about half of that code nicely:

```
for index, item in enumerate(items):
    print(item)
    if index == limit: # There's gotta be a better way.
        break

```

So we've about cut the extra code in half. But there's gotta be a better way.

Can we approximate the below pseudocode behavior?
=================================================

If enumerate took another optional `stop` argument (for example, it takes a `start` argument like this: `enumerate(items, start=1)`) that would, I think, be ideal, but the below doesn't exist (see the [documentation on enumerate here](https://docs.python.org/3/library/functions.html#enumerate)):

```
# hypothetical code, not implemented:
for _, item in enumerate(items, start=0, stop=limit): # `stop` not implemented
    print(item)

```

Note that there would be no need to name the `index` because there is no need to reference it.

Is there an idiomatic way to write the above? How?

A secondary question: why isn't this built into enumerate?

Answer: 
Why not simply use

```
for item in items[:limit]: # or limit+1, depends
    print(item)    # or whatever function of that item.

```

This will only work for some iterables, but since you specified Lists, it works.

It doesn't work if you use Sets or dicts etc.
short solution

```
items = range(10)
limit = 5

for i in items[:limit]: print(i)

```