please help with the issue. I need to compare an element of a loop with a previous element in python 3. The code below gives the error:
TypeError: 'int' object is not subscriptable
for index, (i, j) in enumerate(zip(a_list, b_list)):
if j[index] == j[index-1]:
a = 0
jis element which can be int. So it's not subscriptable. You might use list variable in place ofj(btw, your requirement is not known/clear).integer valueinj. Check what is the value ofjyou are getting, It probably is an integer value.if a_list[index] == a_list[index-1]:or something. But that's obviously not going to work for the first element, sincea_list[0 - 1]is going to look at the last element ofa_list