list(range(0,ceil(len(alist)/size)))))
print(chunk([1,2,3,4,5],2))
输出:[[1,2],[3,4],[5]]
8.压缩
使用python...filter函数,其一般形式为filter(func,iterable)
例子1:
def is_odd(a):
return a%2==1
print(list(filter(is_odd,...[1,2,3,4,5,6,7,8])))
输出:[1,3,5,7]
例子2:
print(list(filter(bool,[False,None,"",0,3,"a"])))
输出:[3,"a"]
9