2024-10-01 00:34:03 发布
网友
l1 = ["a", "b", "c"] l2 = ["a", "b", "c"] for i in l1: print(i) for i in l2: print(i)
输出:aabcbabccabc如何获得这样的输出?:aabbcc
aabcbabccabc
aabbcc
您可以使用zip内置函数。它将返回您传递的所有iterables的i-th item。见zip doc
zip
i-th item
就你而言:
for it in zip(l1, l2): # the * is for extracting the items from it # sep="" does not print any spaces between # end="" does avoid printing a new line at the end print(*it, sep="", end="")
使用zip:
l1 = ["a", "b", "c"] l2 = ["a", "b", "c"] for a, b in zip(l1, l2): print(a) print(b)
如果阵列大小相同,可以执行以下操作:
for i in range((len(l1)): print(l1[i]) print(l2[i])
您可以使用
zip
内置函数。它将返回您传递的所有iterables的i-th item
。见zip doc就你而言:
使用
zip
:如果阵列大小相同,可以执行以下操作:
相关问题 更多 >
编程相关推荐