We're a place where coders share, stay up-to-date and grow their careers.
Oh my, it even works in python!
def stray(arr): count = {} for index, i in enumerate(arr): count[i] = count.setdefault(i, 0) + 1 if index >= 2 and len(count.keys()) > 1: break return next(k for k, v in count.items() if v == 1) from functools import reduce def intstray(arr: [int]): return reduce(lambda x,y: x ^ y, arr) assert(intstray([1, 1, 2]) == 2) #nope..! #assert(intstray([1, 1, 2, 1]) == 2) assert(intstray([17, 17, 3, 17, 17, 17, 17]) == 3) assert(intstray([1, 2, 2]) == 1) assert(stray(["bob", "bob", "bob", "steve", "bob"]) == "steve")
This is one of those moments when I wish gifs worked better on Dev. But yay!
They should work in normal image markdown!
Whaaa?! How did I not know this! ...game changer
Oh my, it even works in python!
This is one of those moments when I wish gifs worked better on Dev. But yay!
They should work in normal image markdown!
Whaaa?! How did I not know this! ...game changer