1

I have 2 different arrays and I need help printing both of them

Route = ["Bus A","Bus B","Bus C","Bus D","Bus E","Bus F"]
DaysLate = [ [1],[2],[3],[4],[5],[6] ]

is there a way I can get this output?

Bus A 1
Bus B 2
Bus C 3
Bus D 4
Bus E 5
Bus F 6
Mehrdad Pedramfar
  • 10,941
  • 4
  • 38
  • 59
J.Doe
  • 27
  • 4
  • Possible duplicate of https://stackoverflow.com/questions/1919044/is-there-a-better-way-to-iterate-over-two-lists-getting-one-element-from-each-l – Jennifer Goncalves Feb 16 '19 at 13:09
  • I dont understand his code, cant be a duplicate because this is simpler? – J.Doe Feb 16 '19 at 13:14
  • Possible duplicate of [Is there a better way to iterate over two lists, getting one element from each list for each iteration?](https://stackoverflow.com/questions/1919044/is-there-a-better-way-to-iterate-over-two-lists-getting-one-element-from-each-l) – Olivier Melançon Feb 16 '19 at 13:17

3 Answers3

2

Try this:

Route = ["Bus A","Bus B","Bus C","Bus D","Bus E","Bus F"]
DaysLate = [ [1],[2],[3],[4],[5],[6] ]

for i,j in zip(Route,DaysLate):
    print(i, j[0])
Mehrdad Pedramfar
  • 10,941
  • 4
  • 38
  • 59
0

Try this:

for i in range(6):
    print(Route[i], DaysLate[i][0])
Heyran.rs
  • 501
  • 1
  • 10
  • 20
0

You can also use the function chain.from_iterable() from itertools module to chain all sublists into a single sequence:

for i, j in zip(Route, itertools.chain.from_iterable(DaysLate)):
    print(i, j)

Alternatively you can use a star * to unpack sublists:

for i, j in zip(Route, DaysLate):
    print(i, *j)
Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73