I have 3 lists,
a = ['1','2','3']
b = ['4','5','6']
c = ['7','8','9']
The output I am trying is,
1 4 7
2 5 8
3 6 9
I have 3 lists,
a = ['1','2','3']
b = ['4','5','6']
c = ['7','8','9']
The output I am trying is,
1 4 7
2 5 8
3 6 9
ungolfed version -))
def list_to_str(lst):
return " ".join(lst)
def handle_multi_lists (*lsts):
return "\n".join(list_to_str(l) for l in lsts)
a = ['1','2','3']
b = ['4','5','6']
c = ['7','8','9']
print(handle_multi_lists(a,b,c))
Try this code . I am also attach the screenshot of the output.
a = ['1','2','3']
b = ['4','5','6']
c = ['7','8','9']
for i in range(0,3):
print(a[i] + "\t" + b[i] + "\t" + c[i])
print("\n")
You could use list comprehension
in order to achieve your requirement.
Since your lists
should have same length property, you can use a for
loop until reach range(len(list[0]))
list = [a, b, c]
print([' '.join([elem[i] for i in range(len(list[0]))]) for elem in list])