我想将二维列表放入函数中,以便它返回一个二维列表,其中每个第二个列表项都组合在一起,如下所示:
List2D = [['a','b','c'], [1, 2, 3]]
def MyFunction(List2D):
...
(some code here)
...
print(TheFinalList)
所需的输出:[['a1','a2','a3'],['b1','b2','b3'],['c1','c2','c3']]
有人删除了正确答案的帖子:
NewList2D = [['a', 'b', 'c'], [1, 2, 3]]
List = [[str(x)+str(y) for y in NewList2D[1]] for x in NewList2D[0]]
print(List)
output: [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
贷记-Nick