python多重嵌套list切片

有一个三层嵌套list,想对最里层切片得到listb

a = [[[1,2],[3,4]],[[5,6],[7,8]]]
b=[[[1],[3]],[[5],[7]]]

使用numpy:

a = [[[1,2],[3,4]],[[5,6],[7,8]]]
import numpy as np
b=list(map(lambda x:[[y] for y in x.tolist()],np.array(a)[:,:,0]))
print(b)

你可能感兴趣的:(python,pycharm,java,c语言)