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.

>>> tda = [['1', '2 ', '3    '], ['longer     ', 'longer    ',
'sort']]
>>> mcw = [[len(r) for r in c] for c in tda]
>>> mcw
[[1, 2, 5], [11, 10, 4]]
>>> mcw = [max([len(r) for r in c]) for c in tda]
>>> mcw
[5, 11]
>>> widest = max(mcw)
>>> widest
11

Is that what you mean?

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to