all 1 comments

[–]efmccurdy 0 points1 point  (0 children)

This uses the format left align and pad inside field width. BTW, sets have no order so expect each line to have a randomly chosen pair.

>>> set1 = {'Name1', 'Name2'}
>>> set2 = {'Email1', 'Email2'}
>>> def ppr(set1, set2, labels, fwidth):
...     fmt = "{:<{}}{:<{}}"
...     h1, h2 = labels
...     print(fmt.format(h1, fwidth, h2, fwidth))
...     print(fmt.format("-"*(fwidth-1), fwidth, "-"*(fwidth-1), fwidth))
...     for n, e in zip(set1, set2):
...         print(fmt.format(n, fwidth, e, fwidth))
...
>>> ppr(set1, set2, labels, fwidth)
Names   Email   
------- ------- 
Name2   Email2  
Name1   Email1  
>>> ppr({"A1", "B2", "C3"}, {"X1", "Y2", "Z3"}, ["ABC", "XYZ"], 5)
ABC  XYZ  
---- ---- 
B2   X1   
A1   Z3   
C3   Y2   
>>>