first_name = ["Johnny", "Joseph", "Mary"]
third_name = ["Mendez", "Nash", "Johanson"]
second_name = ["John", "Allen", "Ann"]
for i in first_name:
for x in second_name:
for y in third_name:
names = i + x + y
我们如何进行输出:
[Johnny John Mendez, Joseph Allen Nash, Mary Ann Johanson]
因为当我循环浏览所有的列表时,我会得到混乱的名字。我们怎样才能确定名字的顺序。first_name second_name third_name
?你知道吗
使用^{} 和^{} :
REPL中的示例:
然后您可以创建一个可能在其他地方使用的函数:
或者更一般的不是硬编码确切的三个名称部分:
REPL示例:
如果列表大小不相等,这将起作用
使用^{} :
zip
函数同时遍历三个列表,并在每次迭代时从每个列表中获取相应的元素。你知道吗相关问题 更多 >
编程相关推荐