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) #result:1,3,5,0,a,b for i in chain(a,b.values()): print(i) #result:1,3,5,0,1,2 c = '2,4,6' for i in chain(a,c): print(i) #result:1,3,5,0,2,4,6