Created
August 30, 2016 17:46
-
-
Save huseyinyilmaz/baff40662aa81d0eac47d7f0056fc9d4 to your computer and use it in GitHub Desktop.
Find first unique element in a list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def get_unique(ls): | |
uniques = set(i | |
for (i, c) in Counter(ls).iteritems() | |
if c == 1) | |
return next((e for e in ls if e in uniques), None) | |
if __name__ == '__main__': | |
print(get_unique([1, 1, 1, 2])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment