列表推导式
li=[[1,2,3],[2,3,4],[3,4,5],[4,5,6]] xx=[[y*y for y in i] for i in li] aa=[y*y for i in li for y in i] print(aa)#[1, 4, 9, 4, 9, 16, 9, 16, 25, 16, 25, 36] print(xx)#[[1, 4, 9], [4, 9, 16], [9, 16, 25], [16, 25, 36]]
a=[{'name':'zhangsan','age':18},{'name':'lisi','age':20}]
d=[[value for value in item.values()] for item in a ]
print(d)#[['zhangsan', 18], ['lisi', 20]]
d=[[key for key in item.keys()] for item in a ]
print(d)#[['name', 'age'], ['name', 'age']]