I need help comparing two lists and returning the indices that they don't match.
a = [0, 1, 1, 0, 0, 0, 1, 0, 1]
b = [0, 1, 1, 0, 1, 0, 1, 0, 0]
indices 4 and 8 don't match and i need to return that as a list [4,8]
I've tried a few methods but they haven't worked for me.
Use zip to iterate over both lists at the same time and enumerate to get the indices during iteration, and write a list comprehension that filters out the indices where the list values don't match:
>>> [i for i, (x, y) in enumerate(zip(a, b)) if x != y]
[4, 8]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With