Python For Og Lecture 69 and 70 - Zip Function
Python For Og Lecture 69 and 70 - Zip Function
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
a = [1,2,3,4]
b = [5,6,7,8]
# i want output ((1, 5), (2, 6), (3, 7), (4, 8))
c = list(zip(a, b))
list(c)
/
# for loop
2/3/2021 Python for O&G Lecture 69 and 70: zip function - Colaboratory
# for loop
for i in c:
print(i)
(1, 5)
(2, 6)
(3, 7)
(4, 8)
for i, j in c:
print(i+ j)
6
8
10
12
Excercise problem
print(s_o)
list(zip(s_w, s_g))
d = list(zip(s_w, s_g))
print(d)
list(zip(*d))
Assignment 18
[(19, 16, 24, 50), (24, 17, 24, 47), (31, 38, 40, 19), (34, 29, 37, 49), (45, 19, 15, 10)]
for i, j, k, l in perm:
print((i+j+k+l)/4)
27.25
28.0
32.0
/
2/3/2021 Python for O&G Lecture 69 and 70: zip function - Colaboratory
37.25
22.25
# let's say I want to do this problem for 9 lists. How would you do that?
[(19, 16, 24, 50), (24, 17, 24, 47), (31, 38, 40, 19), (34, 29, 37, 49), (45, 19, 15, 10)]
for i in perm:
print(sum(i)/len(i))
27.25
28.0
32.0
37.25
22.25
/
2/3/2021 Python for O&G Lecture 69 and 70: zip function - Colaboratory