Enumerate - int object not subscriptable
Sayth Renshaw
flebber.crue at gmail.com
Tue Aug 20 08:00:56 EDT 2019
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
More information about the Python-list
mailing list