MCPcopy Create free account
hub / github.com/ipython/ipython / _find_optimal

Function _find_optimal

IPython/utils/text.py:627–639  ·  view source on GitHub ↗

Calculate optimal info to columnize a list of string

(rlist, row_first=False, separator_size=2, displaywidth=80)

Source from the content-addressed store, hash-verified

625
626
627def _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
642def _get_or_default(mylist, i, default=None):

Callers 1

compute_item_matrixFunction · 0.85

Calls 1

_col_chunksFunction · 0.85

Tested by

no test coverage detected