-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_method.py
41 lines (29 loc) · 1009 Bytes
/
filter_method.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
# I'm going to use the filter method
listNumber = [12, 34, 45, 6, 6, 8, 12, 79]
def number_pair(num):
if num % 2 == 0:
return True
print(list(filter(number_pair, listNumber)))
# using the lambda expression
listNumberTwo = [12, 34, 45, 6, 6, 8, 12, 79]
print(list(filter(lambda x: x % 2 == 0, listNumberTwo)))
# with a class
class Employee:
def __init__(self, name, position, salary):
self.name = name
self.position = position
self.salary = salary
def __str__(self):
return "{} es {} y tiene un salary de {}".format(self.name, self.position, self.salary)
# out of the class
list_Employees = [
Employee("Tom", "Director", 50000),
Employee("John", "vice principal", 30000),
Employee("Tommy", "Manager", 20000),
Employee("Homer", "Admin", 18000),
Employee("Daniel", "Companion", 15000),
Employee("Mark", "Bellboy", 10000),
]
up_salaries = filter(lambda e: e.salary > 17000, list_Employees)
for k in up_salaries:
print(k)