链函数
链函数: chain函数串联a和b,兼顾内存效率同时写法更加优雅
from itertools import chain
a = [1, 3, 5, 0]
b = {'a': 1, 'b': 2}
# 演示一:
for i in chain(a, b):
print(i, end=' ') # 1 3 5 0 a b 1
print()
# 演示二:
print(b.values()) # dict_values([1, 2])
for i in chain(a, b.values()):
print(i, end=' ') # 1 3 5 0 1 2
print()
# 演示三:
c = '2,4,6'
for i in chain(a, c):
print(i, end=' ') # 1 3 5 0 2 , 4 , 6