I have a list of 3 strings, two of which are always equal. I want to find the odd one out. The problems sound super simple but I haven't been able to find a truly elegant way to do it.
For example, the list, lst = ['foo', 'bar', 'foo']
, should return 1
. The way I am currently doing it is this:
f = lambda x, y, z: {(0, 0): 0, (0, 1): 1}.get((x == y, x == z), 2)
ans = f(*lst)
Is there a better way here?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…