Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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_String_List - Fatal编程技术网

从作为序列列表给出的矩形中提取对角线(Python)

从作为序列列表给出的矩形中提取对角线(Python),python,string,list,Python,String,List,我需要帮助更改字符串列表的顺序。 例如: Matrix_List = ['bnnp', 'yior', 'ente', 'femf'] b n n p y i o r e n t e f e m f 我想把它改成这样(比如按照这个方向建立一个新的列表)↘ : b i t f y n m e e f n o e n r p Matrix_list = ['bitf', 'ynm','ee','f','noe','nr','p'] 非常感谢您的帮助。我想您可以使用“for”将所有单个字符输入到

我需要帮助更改字符串列表的顺序。 例如:

Matrix_List = ['bnnp', 'yior', 'ente', 'femf']
b n n p
y i o r
e n t e
f e m f
我想把它改成这样(比如按照这个方向建立一个新的列表)↘ :

b i t f
y n m
e e
f
n o e
n r 
p
Matrix_list = ['bitf', 'ynm','ee','f','noe','nr','p']

非常感谢您的帮助。

我想您可以使用“for”将所有单个字符输入到一个新列表中。然后通过新列表的索引,您可以回忆字母并创建您想要的列表。

您可以这样变换网格

       b n n p
     y i o r
   e n t e
 f e m f
然后使用
zip
检索列:

Matrix_List = ['bnnp', 'yior', 'ente', 'femf']
n = len(Matrix_List)
pad = (n-1) * ['']
padded = [pad[i:] + list(word) + pad[:i] for i, word in enumerate(Matrix_List)]
result = [''.join(column) for column in zip(*padded)]

欢迎来到Stack Overflow!您似乎在要求有人为您编写一些代码。Stack Overflow是一个问答网站,而不是一个代码编写服务。请学习如何编写有效的问题。我不要求代码,我要求指导编写一些代码来做这项工作,可能是递归的,可能是循环的。我想要这个职位:↙ ? 我该怎么做?你能给我解释一下这句话:“padded=[pad[I:][list(word)+pad[:I]for I,word in enumerate(Matrix\u list)]”吗?我理解pad的意思,但是“word in enumerate(Matrix\u list)”不是它的
I,word in enumerate(Matrix\u list)
因此,单词在
word
中,索引在
i
中。对于左下方向,只需在另一个方向填充即可。