Skip to content

Instantly share code, notes, and snippets.

@yunlzheng
Created December 12, 2013 05:12
Show Gist options
  • Select an option

  • Save yunlzheng/7923500 to your computer and use it in GitHub Desktop.

Select an option

Save yunlzheng/7923500 to your computer and use it in GitHub Desktop.
#Your optional code here
#You can import some modules or create additional functions
checkio = lambda d: [x for x in d if d.count(x) > 1]
#Some hints
#You can use list.count(element) method for counting.
#Create new list with non-unique elements
#or remove elements from original list (but it's bad practice for many real cases)
#Loop over original list
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == "__main__":
#assert isinstance(checkio([1]), list), "The result must be a list"
assert checkio([1, 2, 3, 1, 3]) == [1, 3, 1, 3], "1st example"
assert checkio([1, 2, 3, 4, 5]) == [], "2nd example"
assert checkio([5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5], "3rd example"
assert checkio([10, 9, 10, 10, 9, 8]) == [10, 9, 10, 10, 9], "4th example"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment