Console column output in python3
Question: I am trying to create to create a column output for a few lists that differ in
lengths, e.g:

    
    
    list1 = ['hello', 'hello', 'hello', 'hello', 'hello', 'goodbye']
    list2 = ['hello', 'hello', 'hello']
    list3 = ['hello', 'hello', 'hello', 'hello']
    

desired output:

    
    
    hello    hello   hello
    hello    hello   hello
    hello    hello   hello
    hello            hello
    hello
    goodbye
    

The individual lists can be quite long, and the lists are linked in a way as
we are doing matching of items in the lists and printing matches etc. Hence
the need to do it in column format.

I've worked out how to do everything else, apart from printing the desired
output.

I have played around with zip, but from my limited experience it does not seem
to like lists of different lengths, but I could be doing it all wrong of
course. ;-)

Basically I'm stuck. :-(


Answer: Indeed, zip only pairs items up to the shortest iterator. What you are looking
for is

    
    
    itertools.zip_longest
    

That would pair elements from different iterators and use a fillvalue for when
the iterators fall short.

For instance:

    
    
    from itertools import zip_longest
    
    for elems in zip_longest(list1, list2, list3):
        for e in elems:
           print(e or '\t', end=" ")
        print()
    

