-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiltering.py
32 lines (23 loc) · 892 Bytes
/
filtering.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
def is_younger(worker: str) -> bool:
return int(worker['age']) < 18
def get_name(worker: str) -> str:
return worker['name']
if __name__ == '__main__':
import json
with open('json/workers.json', 'r') as f:
data = json.load(f)
# Lists comprehensions
python_devs: list = [
worker for worker in data if worker['language'] == 'python']
ux_designers: list = [
worker for worker in data if worker['position'] == 'UX Designer']
# Lambda - High Order Functions
younger = list(filter(lambda worker: int(worker['age']) < 18, data))
younger_names = list(map(lambda worker: worker['name'], younger))
# Functions - High Order Functions
# younger = list(filter(is_younger, data))
# younger_names = list(map(get_name, younger))
# print(python_devs)
# print(ux_designers)
print(younger)
print(younger_names)