Skip to content

Instantly share code, notes, and snippets.

@huseyinyilmaz
Created August 30, 2016 17:46
Show Gist options
  • Save huseyinyilmaz/baff40662aa81d0eac47d7f0056fc9d4 to your computer and use it in GitHub Desktop.
Save huseyinyilmaz/baff40662aa81d0eac47d7f0056fc9d4 to your computer and use it in GitHub Desktop.
Find first unique element in a list.
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