MCPcopy
hub / github.com/burnash/gspread / fill_gaps

Function fill_gaps

gspread/utils.py:637–679  ·  view source on GitHub ↗

Fill gaps in a list of lists. e.g.,:: >>> L = [ ... [1, 2, 3], ... ] >>> fill_gaps(L, 2, 4) [ [1, 2, 3, ""], ["", "", "", ""] ] :param L: List of lists to fill gaps in. :param rows: Number of rows to fill. :par

(
    L: List[List[Any]],
    rows: Optional[int] = None,
    cols: Optional[int] = None,
    padding_value: Any = "",
)

Source from the content-addressed store, hash-verified

635
636
637def fill_gaps(
638 L: List[List[Any]],
639 rows: Optional[int] = None,
640 cols: Optional[int] = None,
641 padding_value: Any = "",
642) -> List[List[Any]]:
643 """Fill gaps in a list of lists.
644 e.g.,::
645
646 >>> L = [
647 ... [1, 2, 3],
648 ... ]
649 >>> fill_gaps(L, 2, 4)
650 [
651 [1, 2, 3, ""],
652 ["", "", "", ""]
653 ]
654
655 :param L: List of lists to fill gaps in.
656 :param rows: Number of rows to fill.
657 :param cols: Number of columns to fill.
658 :param padding_value: Default value to fill gaps with.
659
660 :type L: list[list[T]]
661 :type rows: int
662 :type cols: int
663 :type padding_value: T
664
665 :return: List of lists with gaps filled.
666 :rtype: list[list[T]]:
667 """
668 try:
669 max_cols = max(len(row) for row in L) if cols is None else cols
670 max_rows = len(L) if rows is None else rows
671
672 pad_rows = max_rows - len(L)
673
674 if pad_rows:
675 L = L + ([[]] * pad_rows)
676
677 return [rightpad(row, max_cols, padding_value=padding_value) for row in L]
678 except ValueError:
679 return [[]]
680
681
682def cell_list_to_rect(cell_list: List["Cell"]) -> List[List[Optional[str]]]:

Callers 3

rangeMethod · 0.85
getMethod · 0.85
_finderMethod · 0.85

Calls 1

rightpadFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…