所以我正在尝试编写一个允许我获取文本文件的脚本, 将布局旋转 90 度并使所有字母保持正确的方向(而不是让字母横向旋转)
是的,如果我有一个像这样的列表:
x = ['the','boy','ate','jam','pie']
如何根据每个列表项中字母的索引位置创建列表。
letters[0] = t,b,a,j,p
letters[1] = h,o,t,a,i
letters[2] = e,y,e,m,e
x = ['tbajp','hotai','eyeme']
我在哪里:
new_list = []
x = ["the","boy","ate","jam","pie"]
y = len(x)
t = 0
while y > 0:
z = len(x[0])
c = 0
while z > 0:
print(x[t][c])
z -= 1
c += 1
y -= 1
t += 1
最佳答案
使用list(zip(*x))的最短方法
:
x = ['the','boy','ate','jam','pie']
rotate_list = [''.join(i) for i in list(zip(*x))]
print(rotate_list)
输出:
['tbajp', 'hotai', 'eyeme']
编辑:
您可以使用以下方法反转rotate_list
:
reversed_strings = [''.join(i)[::-1] for i in list(zip(*x))]
输出:
['pjabt', 'iatoh', 'emeye']
关于Python根据现有列表的字母索引创建列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71922984/