Skip to content

Instantly share code, notes, and snippets.

@denysbutenko
Created September 12, 2014 17:01
Show Gist options
  • Save denysbutenko/a9ae2cf3b490397663dc to your computer and use it in GitHub Desktop.
Save denysbutenko/a9ae2cf3b490397663dc to your computer and use it in GitHub Desktop.
Remove non-unique elements from list
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