Skip to content

Instantly share code, notes, and snippets.

@rvasilevsk
Last active November 6, 2022 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvasilevsk/d17e11209d758bdba6a5f1531e4dba99 to your computer and use it in GitHub Desktop.
Save rvasilevsk/d17e11209d758bdba6a5f1531e4dba99 to your computer and use it in GitHub Desktop.
[table_trim()] #fn #snippet
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