这就是我所拥有的。我想把这两个列表连接在一起
first_name = ['Homer', 'Marge', 'Bart', 'Lisa', 'Maggie',
'Carl', 'Ned', 'Barney', 'Lenny', 'Otto', 'Seymour']
last_name = ['Simpson', 'Simpson', 'Simpson', 'Simpson', 'Simpson',
'Carlson', 'Flanders', 'Gumble', 'Leonard', 'Mann', 'Skinner']
for (i, j) in zip(first_name, last_name):
print (first_name[i] + " " + last_name[j])
但是有一条错误消息说
TypeError: list indices must be integers, not str
在“打印”语句的行上
可以通过以下方式使用Pythonmap function获得所需的输出:
编辑:在使用索引的情况下,但是通过elemenet迭代更好
两个列表长度相同,因此:
循环实际上是遍历元素,而不是索引
相关问题 更多 >
编程相关推荐