Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
转换python列表_Python_Python 3.x_List_Transpose - Fatal编程技术网

转换python列表

转换python列表,python,python-3.x,list,transpose,Python,Python 3.x,List,Transpose,我有一个试图显示为多个列的列列表: 以下是清单: for name in file: worksheet.write(row, col, name) col += 1 以下是创建的输出: ['apples','oranges','bananas','pears'] 我正在尝试将其转置,并将其显示如下: apples oranges bananas pears 谁能给我一个建议,我怎样才能把我的名单转过来。感谢使用加入: join可以做你想做的事 输出: apples ora

我有一个试图显示为多个列的列列表:

以下是清单:

for name in file:
    worksheet.write(row, col, name)
    col += 1
以下是创建的输出:

['apples','oranges','bananas','pears']
我正在尝试将其转置,并将其显示如下:

apples
oranges
bananas
pears
谁能给我一个建议,我怎样才能把我的名单转过来。感谢使用加入:

join可以做你想做的事

输出:

apples
oranges
bananas
pears
apples
oranges
bananas
pears

如果我做对了,你想要这个:

[list(item) for item in your_list]

这将创建一个2d列表,其中的每个项目都位于自己的“行”中

将列增量更改为行增量将解决您的问题

for name in file:
    worksheet.write(row, col, name)
    row += 1
输出:

apples
oranges
bananas
pears
apples
oranges
bananas
pears

尝试了上述操作,但它仍将列表中的每个项目显示在单独的列中,但不会按行进行转换。@hellokee那么所需的输出是什么?我正在尝试将这些值显示在不同的行中,但显示在相同的列中。。我不确定我是否表达了我想要的。如果您参考了我在初始消息中共享的预期输出,则列表中的每个项目都会一个接一个地显示在同一列中。。希望这有帮助。。Tnx@hellokee我的不是这样吗?你能再运行一次吗?