以下代码
from itertools import cycle
from string import ascii_uppercase
letter = cycle(ascii_uppercase)
column1 = 'HELLO'
len_other_columns = len(column1)-1
other_columns = range(len_other_columns)
for letter1 in column1:
while next(letter) != letter1: ...
print(letter1, ' '.join(next(letter) for _ in other_columns))
产生
HIJKL EFGHI LMNOP LMNOP OPQRS
要将结果放置在列表列表或2D数组中,
from itertools import cycle
from string import ascii_uppercase
letter = cycle(ascii_uppercase)
column1 = 'HELLO'
len_other_columns = len(column1)-1
other_columns = range(len_other_columns)
# Initialize the 2D array
two_d_array = [[c] for c in column1]
# similar to the previous
for sublist in two_d_array:
while next(letter) != sl[0]: ...
for _ in other_columns: sublist.append(next(letter))
print(two_d_array)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句