Created
January 15, 2015 10:14
-
-
Save bungoume/dea503cd07eb55d2cebb to your computer and use it in GitHub Desktop.
python unique function
This file contains 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
def uniq(array, callback=None): | |
seen = [] | |
result = [] | |
for obj in array: | |
if callback: | |
key = callback(obj) | |
else: | |
key = obj | |
if key not in seen: | |
seen.append(key) | |
result.append(obj) | |
return result |
Author
bungoume
commented
Jan 15, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment