Search code examples
pythonlisttabular

Table in Python 3.3 from two lists


I have have two lists and I want to print them out in the shell as such:

List 1 name ----- List 2 name 
     1                a
     2                b
     .                .
     .                .

Solution

  • You can do it as:

    a = ['apple', 'banana', 'cat']
    b = ['dinosaur', 'raspberry', 'elephant']
    
    for c,d in zip(a,b):
        print '{:>15}     {:<15}'.format(c,d)
    
    [OUTPUT]
     apple     dinosaur  
    banana     raspberry 
       cat     elephant