Created
December 12, 2013 05:12
-
-
Save yunlzheng/7923500 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #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