Python (zip, lambda, map, shallow copy, deepcopy)
1.zip
数据进行绑定到一起
a = [1, 2, 3]
b = [4, 5, 6]
c = [7, 8, 9]
for k, v, v2 in zip(a, b, c):
print(k, v, v2)
2.lambda, map
lambda
进行输入 :输出简化map
传入函数和可迭代对象可以进行依次进行映射执行
fun = lambda x, y, z: x + y + z
print(list(map(fun, a, b, c)))
3.deepcopy和shallowcopy
- 赋值传的是引用
- shallowcopy是一层拷贝
- deepcopy是深层拷贝
import copy
a = [1, 2, [1, 2]]
b = copy.deepcopy(a) # deep copy
c = copy.copy(a) # shallow copy
print(id(a) == id(b))
print(a == b)
print(id(a[2]) == id(b[2]))
print(a)
print(b)