Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def print_table(data, cols, wide):
- """Prints formatted data on columns of given width. useful for printing grid from list
- param - cols: (how many cols wide) wide: how much padding"""
- n, r = divmod(len(data), cols)
- pat = '{{:{}}}'.format(wide)
- line = '\n'.join(pat * cols for _ in range(n))
- last_line = pat * r
- print(line.format(*data))
- print(last_line.format(*data[n * cols:]))
Advertisement
Add Comment
Please, Sign In to add comment