osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Enumerate - int object not subscriptable


Hi

I want to do basic math with a list.

a = [1, 2, 3, 4, 5, 6, 7, 8]

for idx, num in enumerate(a): 
    print(idx, num)

This works, but say I want to print the item value at the next index as well as the current.

for idx, num in enumerate(a): 
    print(num[idx + 1], num)

I am expecting 2, 1.

But am receiving 

TypeError: 'int' object is not subscriptable

Why?

Cheers

Sayth