-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdictionaries.py
31 lines (28 loc) · 927 Bytes
/
dictionaries.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
class Filter:
def __init__(self, _dict):
self._dict = _dict
def return_all_above_average_value(self):
"""
Returns list with keys where all values above average
"""
average_rating = self.get_average_value()
new_dict = {}
for i in self._dict:
if self._dict[i] >= average_rating:
new_dict[i] = self._dict[i]
return [*new_dict]
def return_all_below_average_value(self):
"""
Returns list with keys where all values below average
"""
average_rating = self.get_average_value()
new_dict = {}
for i in self._dict:
if self._dict[i] <= average_rating:
new_dict[i] = self._dict[i]
return [*new_dict]
def get_average_value(self):
"""
Returns average value
"""
return sum([*self._dict.values()]) / len(self._dict)