osdir.com


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

Enumerate - int object not subscriptable


On 20/08/2019 13:00, Sayth Renshaw wrote:
> Hi
> 
> I want to do basic math with a list.
> 
> 
> 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)

a = [1, 2, 3, 4, 5, 6, 7, 8]
for idx, num in enumerate(a):
    print(a[idx + 1], num)