[Tutor] max(len(item)) for cols
maxnoel_fr at yahoo.fr
Fri Jun 17 13:35:54 CEST 2005
On Jun 17, 2005, at 11:58, 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 :(
>>> a = [[1, 2], [1, 2, 3], [1, 2, 3, 4], ]
>>> max(len(item) for item in a)
If you're running Python 2.3 or lower, add brackets in the last
>>> max([len(item) for item in a])
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting
and sweating as you run through my corridors... How can you challenge
a perfect, immortal machine?"
More information about the Tutor