l1 = ["a", "b", "c"]
l2 = ["a", "b", "c"]
for i in l1:
print(i)
for i in l2:
print(i)
Output: aabcbabccabc
How can I get an output like this?:
aabbcc
You can use the zip
builtin function. It will return the i-th item
of all the iterables you pass. See zip doc
In your case:
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="")
Use zip
:
l1 = ["a", "b", "c"]
l2 = ["a", "b", "c"]
for a, b in zip(l1, l2):
print(a)
print(b)
If the arrays are the same size, you can do something like this:
for i in range((len(l1)):
print(l1[i])
print(l2[i])