Skip to content

Commit a31cb71

Browse files
committed
By Zhao Kun Peng
1 parent 5e23c0a commit a31cb71

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

checkio/eliminate.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#Your optional code here
2+
#You can import some modules or create additional functions
3+
4+
from collections import Counter
5+
def checkio(data: list) -> list:
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+
x=sorted(Counter(data).most_common(),key=lambda x:x[1])
10+
global S
11+
S=[]
12+
for i in list(filter(compare,x)):
13+
S.append(i[0])
14+
l=list(filter(isin,data))
15+
return l
16+
def isin(n):
17+
if n in S:
18+
return True
19+
else:
20+
return False
21+
def compare(n):
22+
if n[1]==1:
23+
return False
24+
return True
25+
26+
#Some hints
27+
#You can use list.count(element) method for counting.
28+
#Create new list with non-unique elements
29+
#Loop over original list
30+
31+
32+
if __name__ == "__main__":
33+
#These "asserts" using only for self-checking and not necessary for auto-testing
34+
assert list(checkio([1, 2, 3, 1, 3])) == [1, 3, 1, 3], "1st example"
35+
assert list(checkio([1, 2, 3, 4, 5])) == [], "2nd example"
36+
assert list(checkio([5, 5, 5, 5, 5])) == [5, 5, 5, 5, 5], "3rd example"
37+
assert list(checkio([10, 9, 10, 10, 9, 8])) == [10, 9, 10, 10, 9], "4th example"
38+
print("It is all good. Let's check it now")

0 commit comments

Comments
 (0)