Module tenlib.transform.table
Functions
def split(data: str, separator: str = '\n', *separators: str, strip: bool = False, empty: bool = False) ‑> list-
Splits the
datawith the firstseparator. Then, splits every row of thedatawith the secondseparator, and so on.Args
data- data to split
separator:str- first separator to split data with
*separators:str- other separators
strip:bool- Whether to strip the rows after the last separation
empty:bool- Whether to keep the empty rows after the first separation
Example
>>> data = '1:2: 3\n4:5:6 \n' >>> split(data, '\n', ':') [['1', '2', ' 3'], ['4', '5', '6 '], []] >>> split(data, '\n', ':', strip=True) [['1', '2', ' 3'], ['4', '5', '6'], []] >>> split(data, '\n', ':', empty=False) [['1', '2', ' 3'], ['4', '5', '6 ']] def join(data, separator='\n', *separators) ‑> str-
Merges the deepest list with the last
separator. Then, merges the obtained sublist with the second to lastseparator, and so on.Example
>>> data = [[1, 2, 3], [4, 5, 6]] >>> join(data, '\n', ':') '1:2:3\n4:5:6' def map(table, **functions) ‑> list-
For every column n in the table, if the keyword argument
_nwas given, apply it to every cell of said column.Args
table:list- A list of lists (a table)
**functions- an
_n:funcmapping
Examples
>>> transform.table.map( ... [[1, 2, 3], [4, 5, 6]], ... _0=lambda x: x+1, ... _2=lambda x: x*2 ... ) [2, 2, 6], [5, 5, 12] def read(data: str, separator: str = '\n', *separators: str, strip: bool = False, empty: bool = False) ‑> list-
Splits the
datawith the firstseparator. Then, splits every row of thedatawith the secondseparator, and so on.Args
data- data to split
separator:str- first separator to split data with
*separators:str- other separators
strip:bool- Whether to strip the rows after the last separation
empty:bool- Whether to keep the empty rows after the first separation
Example
>>> data = '1:2: 3\n4:5:6 \n' >>> split(data, '\n', ':') [['1', '2', ' 3'], ['4', '5', '6 '], []] >>> split(data, '\n', ':', strip=True) [['1', '2', ' 3'], ['4', '5', '6'], []] >>> split(data, '\n', ':', empty=False) [['1', '2', ' 3'], ['4', '5', '6 ']] def write(data, separator='\n', *separators) ‑> str-
Merges the deepest list with the last
separator. Then, merges the obtained sublist with the second to lastseparator, and so on.Example
>>> data = [[1, 2, 3], [4, 5, 6]] >>> join(data, '\n', ':') '1:2:3\n4:5:6'