Last active
November 6, 2022 20:31
-
-
Save rvasilevsk/d17e11209d758bdba6a5f1531e4dba99 to your computer and use it in GitHub Desktop.
[table_trim()] #fn #snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import islice | |
from typing import Iterable, List, Optional, Sequence | |
def table_trim(tbl: Iterable[List], max_rows: Optional[int], max_cols: Optional[int]) -> Sequence[List[str]]: | |
if max_rows is not None: | |
tbl = islice(tbl, max_rows) | |
if max_cols is not None: | |
tbl = (row[:max_cols] for row in tbl) | |
return tbl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment