a=[1,2,3,4,5,6,7] b=[0,2,8,9,10,11,12] a[0] to the end of the element If a[1]==b[1], I want to print out the list a and b that deleted a[1] and b[1].
If you do it like below, the out of range error comes out. I think it's because the number of elements in list a is decreasing.
Thank you.
a=[1,2,3,4,5,6,7]
b=[0,2,8,9,10,11,12]
for i in range(0,len(a))
if a[i]==b[i]:
del a[i]
del b[i]
a = [1,2,3,4,5,6,7]
b = [0,2,8,9,10,11,12]
new_a = []
new_b = []
for a_i, b_i in zip(a, b):
if a_i != b_i:
new_a.append(a_i)
new_b.append(b_i)
© 2025 OneMinuteCode. All rights reserved.