- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27-python-filter-function.py
More file actions
Latest commit
39 lines (25 loc) · 757 Bytes
/
Copy path27-python-filter-function.py
File metadata and controls
39 lines (25 loc) · 757 Bytes
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
numbers=range(0, 101)
defmultiple(number):
ifnumber%5==0:
returnTrue
returnFalse
print(list(filter(multiple, numbers)))
f=filter(multiple, numbers)
next(f)
print(list(filter(lambdanumber: number%5==0, numbers)))
#######################################################################################################################
classPerson:
def__init__(self, name, age):
self.name=name
self.age=age
def__str__(self):
return"{} of {} years".format(self.name, self.age)
people= [
Person("John", 35),
Person("Marta", 25),
Person("Manuel", 12),
Person("Ruck", 15),
]
kids=filter(lambdaperson: person.age<18, people)
forkidinkids:
print(kid)