|
| 1 | +#Your optional code here |
| 2 | +#You can import some modules or create additional functions |
| 3 | + |
| 4 | + |
| 5 | +def checkio(data): |
| 6 | + #Your code here |
| 7 | + #It's main function. Don't remove this function |
| 8 | + #It's used for auto-testing and must return a result for check. |
| 9 | + data1 = [] |
| 10 | + for i in range(len(data)): |
| 11 | + if data.count(data[i]) > 1: |
| 12 | + data1.append(data[i]) |
| 13 | + #replace this for solution |
| 14 | + return data1 |
| 15 | + |
| 16 | +#Some hints |
| 17 | +#You can use list.count(element) method for counting. |
| 18 | +#Create new list with non-unique elements |
| 19 | +#Loop over original list |
| 20 | + |
| 21 | + |
| 22 | +if __name__ == "__main__": |
| 23 | + #These "asserts" using only for self-checking and not necessary for auto-testing |
| 24 | + assert isinstance(checkio([1]), list), "The result must be a list" |
| 25 | + assert checkio([1, 2, 3, 1, 3]) == [1, 3, 1, 3], "1st example" |
| 26 | + assert checkio([1, 2, 3, 4, 5]) == [], "2nd example" |
| 27 | + assert checkio([5, 5, 5, 5, 5]) == [5, 5, 5, 5, 5], "3rd example" |
| 28 | + assert checkio([10, 9, 10, 10, 9, 8]) == [10, 9, 10, 10, 9], "4th example" |
0 commit comments