Python: slices of enumerate

list, python, slice

Solution

You can use `islice`:

from itertools import islice

for i,elm in islice(enumerate(some_list),7,40):
    print i,elm

Problem

I want to iterate within a slice of a list. Also, I want to know the indexes of the element under my iteration. I want to make something like ``` for i, elm in enumerate(test_list)[7:40]: print i, elm #i must start with 7 ``` Alas, it says, that `'enumerate' object has no attribute '__getitem__'` How can I get it in most pythonic way?

Original source