-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_1.py
49 lines (35 loc) · 964 Bytes
/
task_1.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
from collections import defaultdict
import numpy as np
def func(ar):
a = np.median(ar)
b = np.median(np.abs(ar - a))
if np.isnan(b):
msg = 'something is wrong'
raise ValueError(msg)
return b
class Thingy:
def __init__(self):
self._data = defaultdict(lambda: 0)
def _func1(self, a):
if isinstance(a, str):
return [a]
try:
collection = iter(a)
except TypeError:
collection = [a]
return collection
def __call__(self, a):
for x in self._func1(a):
self._data[x] += 1
def __str__(self):
return str(self._data)
def __getitem__(self, item):
return self._data[item]
def __getattr__(self, item):
return self._data[item]
def __iter__(self):
return iter(self.data)
def items(self):
return self._data.items()
def __len__(self):
return len(self._data)