def test_lfilter(self): func = lambda x: x lst = list(builtins.range(10)) results = lfilter(lambda x: x, lst), lengths = 9, expecteds = list(builtins.filter(func, lst)), self.check_results(results, expecteds, lengths)
def test_filter(self): func = lambda x: x lst = list(builtins.range(10)) actual1 = filter(func, lst) actual2 = lfilter(func, lst) actual = [actual1, actual2], lengths = 9, expected = list(builtins.filter(func, lst)), self.check_result(actual, expected, lengths)
def _expand_colspan_rowspan(self, rows, fill_rowspan=True): """Given a list of rows, return a list of rows that properly handle colspan/rowspan Discussion on behavior of fill_rowspan in #17073 Parameters ---------- rows : list of rows, each of which is a list of elements in that row fill_rowspan : boolean Should a rowspan fill every item in the rowspan (True) or only the bottommost element (False)? Default is True. Returns ------- res : list of rows, each of which is a list of elements in that row, respecting colspan/rowspan """ res = [] saved_span = [] for row in rows: extracted_row = self._extract_td(row) cols_text = [ _remove_whitespace(self._text_getter(col)) for col in extracted_row ] col_colspans = [ int(col.get('colspan', 1)) for col in extracted_row ] col_rowspans = [ int(col.get('rowspan', 1)) for col in extracted_row ] # expand cols using col_colspans # maybe this can be done with a list comprehension, dunno cols = list( zip( list( flatten( lmap(lambda text_nc: [text_nc[0]] * text_nc[1], list(zip(cols_text, col_colspans))))), list( flatten( lmap(lambda nc_nr: [nc_nr[1]] * nc_nr[0], list(zip(col_colspans, col_rowspans))))))) # cols is now a list of (text, number of rows) # now insert any previous rowspans for (col, (text, nr)) in saved_span: cols.insert(col, (text, nr)) # save next saved_span def advance_item_to_next_row(item): (col, (text, nr)) = item if nr == 1: return None else: # only keep the text around if fill_rowspan is set return (col, (text if fill_rowspan else '', nr - 1)) saved_span = lfilter( lambda i: i is not None, lmap(advance_item_to_next_row, list(enumerate(cols)))) cols = [text for (text, nr) in cols] # generate cols with text only if any([col != '' for col in cols]): res.append(cols) return res