Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2012
1,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. def mystrlen(s):
  2.         return max(len(line) for line in str(s).split('\n'))
  3.  
  4. def autodetectWidth(data):
  5.     widths = [0]*len(data[0])
  6.     for line in data:
  7.         for i in range(len(line)):
  8.             widths[i] = max(widths[i], mystrlen(line[i]))
  9.     return widths
  10.  
  11. # use: myTable.set_cols_width(autodetectWidth(list_of_rows))
  12. # requires an additional iteration over the data, so won't work with generators etc, use list()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement