【发布时间】:2014-03-11 22:08:43
【问题描述】:
我正在尝试遍历字符串列表:
someplace["Canada", "USA", "England"]
for charNum in range(len(lst)): #charNum the length of the characters
print(lst[charNum])
for country in range(len([charNum])): #country is the the string
print(lst[charNum][country])
我想要达到的输出是这样的:
c U E
a S n
n A g
a l
d a
a n
d
更多细节:
for k in range(len(lst[0])):
print(lst[0][k])
如果运行它会打印出来
c
a
n
a
d
a
这是因为它的索引长度为 0。但我必须遍历其他数字:0、1、2。
我取得了一些进展,我创建了一个嵌套的 for 循环:
for i in range(len(lst)): # length of list
for j in range(len(lst[i])): # length of each string
print(lst[i][j])
【问题讨论】: