如何将列表列表中的第一个值作为单独的列表?
例如:
A = [ [[1,4.9], [2,90],[3,8]], [[2,34],[4,78],[9,10]], [[1,90],[3,100]] ]
结果应为:
B = [ [1,2,3],[2,4,9],[1,3] ]
答案 0 :(得分:2)
In [99]: A = [ [[1,4.9], [2,90],[3,8]], [[2,34],[4,78],[9,10]], [[1,90],[3,100]] ]
In [100]: [[item[0] for item in subl] for subl in A]
Out[100]: [[1, 2, 3], [2, 4, 9], [1, 3]]
答案 1 :(得分:1)
[map(None,*k)[0] for k in A]
[(1,2,3),(2,4,9),(1,3)]
答案 2 :(得分:0)
def getFirstValues(A):
B = list()
for eachListofList in A:
currentList= list()
for eachList in eachListofList:
currentList.append(eachList[0])
B.append(currentList)
return B