[Tutor] max(len(item)) for cols

Kent Johnson kent37 at tds.net
Fri Jun 17 15:01:27 CEST 2005


János Juhász wrote:
> Dear Guys,
> 
> I have a 2D array:
> 
>>>>[['1', '2 ', '3    '], ['longer     ', 'longer    ', 'sort']]
> 
> 
> 
> How can I  get what is the max(len(item)) for the columns ?
> I would like to get a list with the max_col_width values.
> 
> I hope that, it can wrote with some nice list comprehension, but I can't do
> that :(

Ah, thanks jfouhy for correctly understanding the question!

If you are doing this because you want to pretty-print a table, you may be interested in this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662

Kent



More information about the Tutor mailing list