forked from n00blet/CheckIO-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
non-unique-elements.py
28 lines (23 loc) · 1015 Bytes
/
non-unique-elements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#Your optional code here
#You can import some modules or create additional functions
def checkio(data):
#Your code here
#It's main function. Don't remove this function
#It's using for auto-testing and must return a result for check.
newlst=[]
for i in data:
if data.count(i)>1:
newlst.append(i)
#replace this for solution
return newlst
#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 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"