align on char

Jeff Epler jepler at unpythonic.net
Thu Jun 17 15:00:36 EDT 2004


>>> def align(seq, sep=":"):
...     seq = [i.split(sep, 1) for i in seq]
...     width = max([len(i[0]) for i in seq])
...     return ["%s:%s" % (a.ljust(width), b) for a, b in seq]
... 
>>> lines = (
...   'user1 : John Hunter',
...   'another user : Bill Bragg',
...   'yet on more : Hi There',  
... )
>>> for l in align(lines): print l;
... 
user1        : John Hunter
another user : Bill Bragg
yet on more  : Hi There

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040617/e0dee665/attachment.sig>


More information about the Python-list mailing list