align on char

Duncan Booth me at privacy.net
Fri Jun 18 04:24:12 EDT 2004


Tor Iver Wilhelmsen <tor.iver.wilhelmsen at broadpark.no> wrote in 
news:u4qparl23.fsf at broadpark.no:

> Jeff Epler <jepler at unpythonic.net> writes:
> 
>> ...     width = max([len(i[0]) for i in seq])
>> ...     return ["%s:%s" % (a.ljust(width), b) for a, b in seq]
> 
> You can also do a
>    fmt = "%" + str(-max) + "s : %s"
>    return [fmt % (a, b) for a, b in seq]
> 
> instead of that last line. Dunno if that's more readable, though. :)

Or a little less contorted:

     return ["%-*s:%s" % (width, a, b) for a, b in seq]



More information about the Python-list mailing list