-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip_demo.py
More file actions
48 lines (37 loc) · 1 KB
/
zip_demo.py
File metadata and controls
48 lines (37 loc) · 1 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
# zip
def demo1():
weight = [70, 60, 48]
height = [170, 175, 161]
bmi = []
for i in range(len(weight)):
bmi.append(weight[i] / (height[i] / 100) ** 2)
return bmi
def demo2():
weight = [70, 60, 48]
height = [170, 175, 161]
bmi = []
for w, h in zip(weight, height):
# print(w, h)
bmi.append(w / (h / 100) ** 2)
return bmi
def demo3():
weight = [70, 60, 48]
height = [170, 175, 161]
return [w / (h / 100) ** 2 for w, h in zip(weight, height)]
def demo4():
weight = [70, 60, 48]
height = [170, 175, 161]
name = ["Leo", "Ben", "Peter"]
return [{n: w / (h / 100) ** 2} for w, h, n in zip(weight, height, name)]
def demo5():
weight = [70, 60, 48]
height = [170, 175, 161]
name = ["Leo", "Jane", "Peter"]
gender = ["M", "F", "M"]
return [{n: w / (h / 100) ** 2} for w, h, n, g in zip(weight, height, name, gender) if
g == "M"]
print(demo1())
print(demo2())
print(demo3())
print(demo4())
print(demo5())