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
     .                .
     .                .
有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top