List manipulation in Python - growing the elements' list
我定义:
1 | A = [[1, 2], [3, 4], [5, 6]] |
生产线生产的是什么:
1 | B = [['hello', [1, 2]], ['hello', [3, 4]], ['hello', [5, 6]]] |
号
您可以将
1 2 3 4 5 | >>> add = 'hello' >>> A = [[1, 2], [3, 4], [5, 6]] >>> [[add, x] for x in A] [['hello', [1, 2]], ['hello', [3, 4]], ['hello', [5, 6]]] # or [[add] + [x] for x in A] |
这可能有帮助:
1 | B = zip(['hello'] * len(A), A) |
号
这将产生以下结果:
1 | B = list(map(list, zip(['hello'] * len(A), A))) |