-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_duplicates.py
50 lines (35 loc) · 1.16 KB
/
remove_duplicates.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import functools
from test_framework import generic_test
from test_framework.test_utils import enable_executor_hook
class Name:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
def __lt__(self, other):
return (
self.first_name < other.first_name
if self.first_name != other.first_name
else self.last_name < other.last_name
)
def eliminate_duplicate(A):
A.sort()
idx = 1
for x in A[1:]:
if x != A[idx-1]:
A[idx] = x
idx += 1
del A[:idx]
@enable_executor_hook
def eliminate_duplicate_wrapper(executor, names):
names = [Name(*x) for x in names]
executor.run(functools.partial(eliminate_duplicate, names))
return names
def comp(expected, result):
return all([
e == r.first_name for (e, r) in zip(sorted(expected), sorted(result))
])
if __name__ == '__main__':
exit(
generic_test.generic_test_main("remove_duplicates.py",
'remove_duplicates.tsv',
eliminate_duplicate_wrapper, comp))