- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path28-python-map-function.py
More file actions
Latest commit
67 lines (42 loc) · 1.38 KB
/
Copy path28-python-map-function.py
File metadata and controls
67 lines (42 loc) · 1.38 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
numbers=range(0, 101)
defdouble(number):
returnnumber*2
doubled_iterator=map(double, numbers)
print(next(doubled_iterator))
print(list(doubled_iterator))
print(list(map(lambdax: x*2, numbers)))
#######################################################################################################################
a= [1, 2, 3, 4, 5]
b= [6, 7, 8, 9, 10]
print(list(map(lambdax, y: x*y, a, b)))
#######################################################################################################################
c= [11, 12, 13, 14, 15]
print(list(map(lambdax, y, z: x*y*z, a, b, c)))
#######################################################################################################################
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),
]
defincrement_age(human):
human.age+=1
returnhuman
people=map(increment_age, people)
forpersoninpeople:
print(person)
people= [
Person("John", 35),
Person("Marta", 25),
Person("Manuel", 12),
Person("Ruck", 15),
]
people=map(lambdahuman: Person(human.name, human.age+1), people)
forpersoninpeople:
print(person)