I have two n-length tuples and I need to check whether all the elements in the same position are the same except for the element in position w. This is what I wrote:
if all(tup1[i] == tup2[i] for i in xrange(n) if i != w):
...
In order to avoid the loop (since this piece of code will be used many times), I tried to use slicing. Unfortunately, this doesn't work:
if tup1[w-1:w-n:-1] == tup2[w-1:w-n:-1]:
...
Am I obliged to write something like this?
if tup1[:w-1] == tup2[:w-1] and tup1[w+1:] == tup2[w+1:]
Isn't there a more elegant methodd?
Or both loop and slicing are no good and there is a better way of obtaining the result I'm looking for? (I can't use filter because there may be elements with the same value of the one in position w)