给定列表[[1],[3,5],[],[1,9],[3,5],[9,7],[1,9]]
,如何将其与[(0,[1]), (1,[3,5]), (2,[]), (3,[1,9]), (4,[3,5]), (5,[9,7]), (6,[1,9])]
答案 0 :(得分:5)
您可以使用zip
zip [0..] theList
例如
zip [0..] [[1],[3,5],[],[1,9],[3,5],[9,7],[1,9]]
产量
[(0,[1]), (1,[3,5]), (2,[]), (3,[1,9]), (4,[3,5]), (5,[9,7]), (6,[1,9])]