You cannot avoid iterating over lists, but you can do it with understanding and get an elegant solution:
next( (idx, x, y) for idx, (x, y) in enumerate(zip(list1, list2)) if x!=y )
If you like something less single-line, you can break it down like this
coupled_idx = enumerate(zip(list1, list2)) res = next( idx for idx, (x, y) in coupled_idx if x!=y )
EDIT:
as an addition, if you need to check the case where the two lists can be completely equal, you can add a second parameter to the next function, which tells it what it returns if the index is not found. The most common option is to return None:
coupled_idx = enumerate(zip(list1, list2)) res = next( (idx for idx, (x, y) in coupled_idx if x!=y), None )
Note that you need to enclose the generator expression between the brackets, because this is not the only function argument in this call.
To add a bit of fun, you can also ask the nth other pair by linking the expressions. For example, this gives you all pairs up to the fifth (filling None if the pair is absent)
coupled_idx = enumerate(zip(list1, list2)) coupler = (idx for idx, (x, y) in coupled_idx if x!=y) res = [ next(coupler, None) for _ in range(5) ]
EDIT2:
Such a solution actually creates a copy of both lists through a zip function. If you need to avoid this, you can use the izip function from the itertools module.
And about the fun part, you can only select solution certificates using the islice function from the same module