Calculate optimal info to columnize a list of string
(rlist, row_first=False, separator_size=2, displaywidth=80)
| 625 | |
| 626 | |
| 627 | def _find_optimal(rlist, row_first=False, separator_size=2, displaywidth=80): |
| 628 | """Calculate optimal info to columnize a list of string""" |
| 629 | for max_rows in range(1, len(rlist) + 1): |
| 630 | col_widths = list(map(max, _col_chunks(rlist, max_rows, row_first))) |
| 631 | sumlength = sum(col_widths) |
| 632 | ncols = len(col_widths) |
| 633 | if sumlength + separator_size * (ncols - 1) <= displaywidth: |
| 634 | break |
| 635 | return {'num_columns': ncols, |
| 636 | 'optimal_separator_width': (displaywidth - sumlength) // (ncols - 1) if (ncols - 1) else 0, |
| 637 | 'max_rows': max_rows, |
| 638 | 'column_widths': col_widths |
| 639 | } |
| 640 | |
| 641 | |
| 642 | def _get_or_default(mylist, i, default=None): |
no test coverage detected