Created
September 12, 2014 17:01
-
-
Save denysbutenko/a9ae2cf3b490397663dc to your computer and use it in GitHub Desktop.
Remove non-unique elements from list
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 remove_non_unique_values(test): | |
return [el for el in test if test.count(el) > 1] | |
if __name__ == '__main__': | |
list_1 = [1, 2, 3, 1, 3] | |
list_2 = [1, 2, 3, 4, 5] | |
list_3 = [5, 5, 5, 5, 5] | |
list_4 = [10, 9, 10, 10, 9, 8] | |
print "====" | |
print "Input >> Output" | |
for test_list in [list_1, list_2, list_3, list_4]: | |
print "{0} >> {1}".format(test_list, | |
remove_non_unique_values(test_list)) | |
print "====" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment