-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.py
37 lines (29 loc) · 1.03 KB
/
utils.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
from functools import reduce
class Counter:
def __init__(self):
self.success_count = 0
self.skip_count = 0
self.fail_count = 0
self.first_fail = None
self.first_skip = None
def success(self):
self.success_count += 1
def skip(self, message):
self.skip_count += 1
if self.first_skip is None:
self.first_skip = message
def fail(self, message):
self.fail_count += 1
if self.first_fail is None:
self.first_fail = message
def results(self):
print("{} success; {} fail; {} skipped".format(self.success_count, self.fail_count, self.skip_count))
if self.first_fail:
print("first fail: {}".format(self.first_fail))
if self.first_skip:
print("first skip: {}".format(self.first_skip))
def remove_duplicates(l):
"removes duplicates in a list while maintaining insertion order"
if not l:
return []
return reduce(lambda a, b: b[0] in a and a or a + b, [[i] for i in l])