【发布时间】:2020-05-10 11:59:24
【问题描述】:
我有 2 个列表(x 和 y),我想在 x、y 中输出(只是打印输出)。我可以知道怎么做吗?我是否需要一个循环来遍历 x 和 y 列表中的每个项目?
input :
x = [['A', 'B'], ['C', 'D'], ['F', 'G']]
y = [['L', 'M'], ['J', 'K'], ['O', 'P', 'Q']]
output :
x, y format
['A', 'B'] ['L', 'M']
['C', 'D'] ['J', 'K']
['F', 'G'] ['O', 'P', 'Q']
我得到的最接近如下:
for row in x:
n = []
for loop in y :
for x in loop :
n.append(x)
print(' '.join(row).strip().split()) , n
Output :
['A', 'B'] ['L', 'M']
['A', 'B'] ['L', 'M', 'J', 'K']
['A', 'B'] ['L', 'M', 'J', 'K', 'O', 'P', 'Q']
['C', 'D'] ['L', 'M']
['C', 'D'] ['L', 'M', 'J', 'K']
['C', 'D'] ['L', 'M', 'J', 'K', 'O', 'P', 'Q']
['F', 'G'] ['L', 'M']
['F', 'G'] ['L', 'M', 'J', 'K']
['F', 'G'] ['L', 'M', 'J', 'K', 'O', 'P', 'Q']
【问题讨论】:
标签: python list dataframe tuples