0

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
Zedaiq
  • 285
  • 1
  • 3
  • 10

4 Answers4

1

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))
marmeladze
  • 6,468
  • 3
  • 24
  • 45
0

You can use the zip method in python to combine multiple list:

EX:

a = ['1','2','3']
b = ['4','5','6']
c = ['7','8','9']

for i in zip(a, b, c):
    print " ".join(i)

1 4 7
2 5 8
3 6 9
Rakesh
  • 81,458
  • 17
  • 76
  • 113
0

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")

enter image description here

Usman
  • 1,983
  • 15
  • 28
0

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])
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128