Reputation:
I know how to print a list vertically :
for item in items:
print(item)
Output :
43435
23423
however I want to put another list (called items2) next to each other so the out put is like this :
43435 a
23423 a
how can I do this in the simplest way ?
EDIT:
86947367 banana
2 10
78364721 apple
2 6
Upvotes: 0
Views: 15494
Reputation: 81594
Use zip
:
list_a = [43435, 23423]
list_b = ['a', 'b']
for item_a, item_b in zip(list_a, list_b):
print(item_a, item_b)
>> 43435 a
23423 b
This can be generalized to a varying number of lists, as long as you keep your lists in a list:
list_a = [43435, 23423]
list_b = ['a', 'b']
list_c = ['ca', 'cb']
list_of_lists = [list_a, list_b, list_c]
for a in zip(*list_of_lists):
print(*a)
>> 43435 a ca
23423 b cb
Upvotes: 5