DEV Community

Discussion on: Coding Puzzles: Week of 4/8

Collapse
 
threeheadedcerb profile image
russ

Looks a bit messy, but I was going for something that might not be too inefficient with a large input array

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)