MCPcopy Create free account
hub / github.com/astanin/python-tabulate / _prepend_row_index

Function _prepend_row_index

tabulate/__init__.py:1431–1448  ·  view source on GitHub ↗

Add a left-most index column.

(rows, index)

Source from the content-addressed store, hash-verified

1429
1430
1431def _prepend_row_index(rows, index):
1432 """Add a left-most index column."""
1433 if index is None or index is False:
1434 return rows
1435 if isinstance(index, Sized) and len(index) != len(rows):
1436 raise ValueError(
1437 "index must be as long as the number of data rows: "
1438 + f"len(index)={len(index)} len(rows)={len(rows)}"
1439 )
1440 sans_rows, separating_lines = _remove_separating_lines(rows)
1441 new_rows = []
1442 index_iter = iter(index)
1443 for row in sans_rows:
1444 index_v = next(index_iter)
1445 new_rows.append([index_v] + list(row))
1446 rows = new_rows
1447 _reinsert_separating_lines(rows, separating_lines)
1448 return rows
1449
1450
1451def _bool(val):

Callers 1

_normalize_tabular_dataFunction · 0.85

Calls 2

_remove_separating_linesFunction · 0.85

Tested by

no test coverage detected