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
3

3 Answers 3

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])
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

for i in range(6):
    print(Route[i], DaysLate[i][0])

2 Comments

Will this work perfectly if the length of the list is greater than 6?
oh ok sorry it was because I forgot the indent, works
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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.