From 94f80bb8ed5d9a0e9bec288617d084eda60cba4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 7 Sep 2024 18:49:53 +0200 Subject: [PATCH] fixing most ruff PERF4 warnings in combinat --- src/sage/combinat/composition_tableau.py | 5 +--- src/sage/combinat/diagram.py | 9 +++---- src/sage/combinat/diagram_algebras.py | 10 ++++---- src/sage/combinat/dlx.py | 5 +--- src/sage/combinat/finite_state_machine.py | 6 ++--- src/sage/combinat/free_dendriform_algebra.py | 10 ++++---- src/sage/combinat/free_prelie_algebra.py | 10 ++++---- src/sage/combinat/gelfand_tsetlin_patterns.py | 24 +++++++------------ src/sage/combinat/graph_path.py | 6 +---- src/sage/combinat/integer_vector.py | 10 ++++---- src/sage/combinat/knutson_tao_puzzles.py | 9 +++---- src/sage/combinat/misc.py | 8 ++----- src/sage/combinat/parallelogram_polyomino.py | 14 ++++------- src/sage/combinat/partition_algebra.py | 13 ++++------ src/sage/combinat/ribbon_shaped_tableau.py | 11 ++++----- src/sage/combinat/rsk.py | 6 ++--- src/sage/combinat/shifted_primed_tableau.py | 8 ++++--- src/sage/combinat/skew_partition.py | 21 +++++++--------- src/sage/combinat/skew_tableau.py | 23 ++++++++---------- src/sage/combinat/specht_module.py | 18 +++++--------- src/sage/combinat/symmetric_group_algebra.py | 12 ++++------ src/sage/combinat/tableau.py | 22 ++++++++--------- src/sage/combinat/tableau_tuple.py | 11 ++++----- 23 files changed, 103 insertions(+), 168 deletions(-) diff --git a/src/sage/combinat/composition_tableau.py b/src/sage/combinat/composition_tableau.py index e90fe55f6a5..1e05da84c4e 100644 --- a/src/sage/combinat/composition_tableau.py +++ b/src/sage/combinat/composition_tableau.py @@ -211,10 +211,7 @@ def descent_set(self): sage: CompositionTableau([[1],[3,2],[4,4]]).descent_set() [1, 3] """ - cols = {} - for row in self: - for col, i in enumerate(row): - cols[i] = col + cols = {i: col for row in self for col, i in enumerate(row)} return sorted(i for i in cols if i + 1 in cols and cols[i + 1] >= cols[i]) def descent_composition(self): diff --git a/src/sage/combinat/diagram.py b/src/sage/combinat/diagram.py index f5b8f9ad864..cc3c1dfe0b6 100644 --- a/src/sage/combinat/diagram.py +++ b/src/sage/combinat/diagram.py @@ -336,12 +336,9 @@ def _latex_(self): lr = r'\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}' - array = [] - for i in range(self._n_rows): - row = [] - for j in range(self._n_cols): - row.append("\\phantom{x}" if (i, j) in self else None) - array.append(row) + array = [[("\\phantom{x}" if (i, j) in self else None) + for j in range(self._n_cols)] + for i in range(self._n_rows)] def end_line(r): # give the line ending to row ``r`` diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py index 364a55c74c9..6410a4a93ea 100644 --- a/src/sage/combinat/diagram_algebras.py +++ b/src/sage/combinat/diagram_algebras.py @@ -3013,7 +3013,7 @@ def jucys_murphy_element(self, i): sage: L = [P.L(i/2) for i in range(1,2*k+1)] sage: all(x.dual() == x for x in L) True - sage: all(x * y == y * x for x in L for y in L) # long time + sage: all(x * y == y * x for x, y in Subsets(L, 2)) # long time True sage: Lsum = sum(L) sage: gens = [P.s(i) for i in range(1,k)] @@ -3045,13 +3045,13 @@ def jucys_murphy_element(self, i): The same tests for a half integer partition algebra:: - sage: k = 9/2 + sage: k = 7/2 sage: R. = QQ[] sage: P = PartitionAlgebra(k, n) sage: L = [P.L(i/2) for i in range(1,2*k+1)] sage: all(x.dual() == x for x in L) True - sage: all(x * y == y * x for x in L for y in L) # long time + sage: all(x * y == y * x for x, y in Subsets(L, 2)) # long time True sage: Lsum = sum(L) sage: gens = [P.s(i) for i in range(1,k-1/2)] @@ -5847,11 +5847,9 @@ def to_Brauer_partition(l, k=None): True """ L = to_set_partition(l, k=k) - L2 = [] paired = [] not_paired = [] - for i in L: - L2.append(list(i)) + L2 = (list(i) for i in L) for i in L2: if len(i) > 2: raise ValueError("blocks must have size at most 2, but {} has {}".format(i, len(i))) diff --git a/src/sage/combinat/dlx.py b/src/sage/combinat/dlx.py index 383dda056be..d25f7414d0d 100644 --- a/src/sage/combinat/dlx.py +++ b/src/sage/combinat/dlx.py @@ -484,10 +484,7 @@ def AllExactCovers(M): ones = [] r = 1 # damn 1-indexing for R in M.rows(): - row = [] - for i in range(len(R)): - if R[i]: - row.append(i + 1) # damn 1-indexing + row = [i for i, Ri in enumerate(R, start=1) if Ri] ones.append([r, row]) r += 1 for s in DLXMatrix(ones): diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index 96d35859873..2750ea15e9c 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -9437,9 +9437,9 @@ def graph(self, edge_labels='words_in_out'): transitions = state.transitions if not transitions: isolated_vertices.append(state.label()) - for t in transitions: - graph_data.append((t.from_state.label(), t.to_state.label(), - label_fct(t))) + graph_data.extend((t.from_state.label(), t.to_state.label(), + label_fct(t)) + for t in transitions) G = DiGraph(graph_data, multiedges=True, loops=True) G.add_vertices(isolated_vertices) diff --git a/src/sage/combinat/free_dendriform_algebra.py b/src/sage/combinat/free_dendriform_algebra.py index 2acfee1b337..4be2c514778 100644 --- a/src/sage/combinat/free_dendriform_algebra.py +++ b/src/sage/combinat/free_dendriform_algebra.py @@ -939,14 +939,12 @@ def merge(self, other): return self ret = list(self.vars) cur_vars = set(ret) - for v in other.vars: - if v not in cur_vars: - ret.append(v) + ret.extend(v for v in other.vars if v not in cur_vars) return DendriformFunctor(Alphabet(ret)) - else: - return None - def _repr_(self): + return None + + def _repr_(self) -> str: """ TESTS:: diff --git a/src/sage/combinat/free_prelie_algebra.py b/src/sage/combinat/free_prelie_algebra.py index 1ea7d3274a1..6e7525d8b23 100644 --- a/src/sage/combinat/free_prelie_algebra.py +++ b/src/sage/combinat/free_prelie_algebra.py @@ -1023,14 +1023,12 @@ def merge(self, other): return self ret = list(self.vars) cur_vars = set(ret) - for v in other.vars: - if v not in cur_vars: - ret.append(v) + ret.extend(v for v in other.vars if v not in cur_vars) return PreLieFunctor(Alphabet(ret)) - else: - return None - def _repr_(self): + return None + + def _repr_(self) -> str: """ TESTS:: diff --git a/src/sage/combinat/gelfand_tsetlin_patterns.py b/src/sage/combinat/gelfand_tsetlin_patterns.py index be4e236b099..5c3c485e549 100644 --- a/src/sage/combinat/gelfand_tsetlin_patterns.py +++ b/src/sage/combinat/gelfand_tsetlin_patterns.py @@ -302,11 +302,9 @@ def boxed_entries(self) -> tuple: sage: G.boxed_entries() ((1, 0),) """ - ret = [] - for i in range(1, len(self)): - for j in range(len(self[i])): - if self[i][j] == self[i - 1][j]: - ret.append((i, j)) + ret = [(i, j) for i in range(1, len(self)) + for j, selfij in enumerate(self[i]) + if selfij == self[i - 1][j]] return tuple(ret) @cached_method @@ -324,11 +322,9 @@ def circled_entries(self) -> tuple: sage: G.circled_entries() ((1, 1), (2, 0)) """ - ret = [] - for i in range(1, len(self)): - for j in range(len(self[i])): - if self[i][j] == self[i - 1][j + 1]: - ret.append((i, j)) + ret = [(i, j) for i in range(1, len(self)) + for j, selfij in enumerate(self[i]) + if selfij == self[i - 1][j + 1]] return tuple(ret) @cached_method @@ -349,11 +345,9 @@ def special_entries(self) -> tuple: sage: G.special_entries() ((2, 0),) """ - ret = [] - for i in range(1, len(self)): - for j in range(len(self[i])): - if self[i-1][j] > self[i][j] and self[i][j] > self[i-1][j+1]: - ret.append((i, j)) + ret = [(i, j) for i in range(1, len(self)) + for j, selfij in enumerate(self[i]) + if self[i - 1][j] > selfij > self[i - 1][j + 1]] return tuple(ret) def number_of_boxes(self) -> int: diff --git a/src/sage/combinat/graph_path.py b/src/sage/combinat/graph_path.py index 2fb255579dd..df84b1acdf7 100644 --- a/src/sage/combinat/graph_path.py +++ b/src/sage/combinat/graph_path.py @@ -236,11 +236,7 @@ def paths_from_source_to_target(self, source, target): [[2, 3, 4], [2, 4]] """ source_paths = self.outgoing_paths(source) - paths = [] - for path in source_paths: - if path[-1] == target: - paths.append(path) - return paths + return [path for path in source_paths if path[-1] == target] def paths(self): """ diff --git a/src/sage/combinat/integer_vector.py b/src/sage/combinat/integer_vector.py index 516d2114ffc..6848609cf5d 100644 --- a/src/sage/combinat/integer_vector.py +++ b/src/sage/combinat/integer_vector.py @@ -1174,19 +1174,17 @@ def _list_rec(self, n, k): EXAMPLES:: sage: IV = IntegerVectors(2,3) - sage: IV._list_rec(2,3) + sage: list(IV._list_rec(2,3)) [(2, 0, 0), (1, 1, 0), (1, 0, 1), (0, 2, 0), (0, 1, 1), (0, 0, 2)] """ - res = [] - if k == 1: - return [(n, )] + yield (n,) + return for nbar in range(n + 1): n_diff = n - nbar for rest in self._list_rec(nbar, k - 1): - res.append((n_diff,) + rest) - return res + yield (n_diff,) + rest def __iter__(self): """ diff --git a/src/sage/combinat/knutson_tao_puzzles.py b/src/sage/combinat/knutson_tao_puzzles.py index e1e4f746f42..f7a7c513c52 100644 --- a/src/sage/combinat/knutson_tao_puzzles.py +++ b/src/sage/combinat/knutson_tao_puzzles.py @@ -2064,12 +2064,9 @@ def _fill_piece(self, nw_label, ne_label, pieces) -> list[PuzzlePiece]: sage: ps._fill_piece('0', '0', ps._bottom_deltas) [0/0\0] """ - output = [] - for piece in pieces: - if (piece['north_west'] == nw_label and - piece['north_east'] == ne_label): - output.append(piece) - return output + return [piece for piece in pieces + if (piece['north_west'] == nw_label and + piece['north_east'] == ne_label)] @cached_method def _fill_strip(self, nw_labels, ne_label, pieces, final_pieces=None): diff --git a/src/sage/combinat/misc.py b/src/sage/combinat/misc.py index 404c032a8dc..d04b615be80 100644 --- a/src/sage/combinat/misc.py +++ b/src/sage/combinat/misc.py @@ -202,11 +202,7 @@ def _monomial_exponent_to_lower_factorial(me, x): sage: _monomial_exponent_to_lower_factorial(([2,2,2]),a) x^2*y^2*z^2 - x^2*y^2*z - x^2*y*z^2 - x*y^2*z^2 + x^2*y*z + x*y^2*z + x*y*z^2 - x*y*z """ - terms = [] - for i in range(len(me)): - for j in range(me[i]): - terms.append( x[i]-j ) - return prod(terms) + return prod(x[i] - j for i, mei in enumerate(me) for j in range(mei)) def umbral_operation(poly): @@ -235,7 +231,7 @@ def umbral_operation(poly): exponents = poly.exponents() coefficients = poly.coefficients() length = len(exponents) - return sum( [coefficients[i]*_monomial_exponent_to_lower_factorial(exponents[i],x) for i in range(length)] ) + return sum(coefficients[i]*_monomial_exponent_to_lower_factorial(exponents[i], x) for i in range(length)) class IterableFunctionCall: diff --git a/src/sage/combinat/parallelogram_polyomino.py b/src/sage/combinat/parallelogram_polyomino.py index ed9308e82e9..c60c72c10d2 100644 --- a/src/sage/combinat/parallelogram_polyomino.py +++ b/src/sage/combinat/parallelogram_polyomino.py @@ -1974,12 +1974,9 @@ def widths(self) -> list: sage: pp.widths() [] """ - widths = [] uw = self.upper_widths() lw = self.lower_widths() - for i in range(len(lw)): - widths.append(uw[i] - lw[i]) - return widths + return [up - lo for up, lo in zip(uw, lw)] def degree_convexity(self) -> int: r""" @@ -3387,11 +3384,10 @@ def get_BS_nodes(self): sage: pp.set_options(drawing_components=dict(tree=True)) sage: view(pp) # not tested """ - result = [] - for h in range(1, self.height()): - result.append(self._get_node_position_at_row(h)) - for w in range(1, self.width()): - result.append(self._get_node_position_at_column(w)) + result = [self._get_node_position_at_row(h) + for h in range(1, self.height())] + result.extend(self._get_node_position_at_column(w) + for w in range(1, self.width())) return result def get_right_BS_nodes(self): diff --git a/src/sage/combinat/partition_algebra.py b/src/sage/combinat/partition_algebra.py index f0d15115ac9..91e79be4cbc 100644 --- a/src/sage/combinat/partition_algebra.py +++ b/src/sage/combinat/partition_algebra.py @@ -364,9 +364,7 @@ def __iter__(self): True """ for p in Permutations(self.k): - res = [] - for i in range(self.k): - res.append(Set([i + 1, -p[i]])) + res = [Set([i, -pi]) for i, pi in enumerate(p, start=1)] yield self.element_class(self, res) @@ -433,10 +431,7 @@ def __iter__(self): {{1, -3}, {2, -2}, {4, -4}, {3, -1}}] """ for p in Permutations(self.k): - res = [] - for i in range(self.k): - res.append(Set([i + 1, -p[i]])) - + res = [Set([i, -pi]) for i, pi in enumerate(p, start=1)] res.append(Set([self.k + 1, -self.k - 1])) yield self.element_class(self, res) @@ -1941,8 +1936,8 @@ def to_set_partition(l, k=None): to_be_added -= spart sp.append(spart) - for singleton in to_be_added: - sp.append(Set([singleton])) + sp.extend(Set([singleton]) + for singleton in to_be_added) return Set(sp) diff --git a/src/sage/combinat/ribbon_shaped_tableau.py b/src/sage/combinat/ribbon_shaped_tableau.py index d33cc115396..dd7218c899c 100644 --- a/src/sage/combinat/ribbon_shaped_tableau.py +++ b/src/sage/combinat/ribbon_shaped_tableau.py @@ -350,18 +350,17 @@ def from_permutation(self, p): [[1, 2], [3]], [[1], [2], [3]]] """ - if p == []: + if not p: return self.element_class(self, []) comp = p.descents() - if comp == []: + if not comp: return self.element_class(self, [p[:]]) - r = [] - r.append([p[j] for j in range(comp[0])]) - for i in range(len(comp) - 1): - r.append([p[j] for j in range(comp[i], comp[i + 1])]) + r = [[p[j] for j in range(comp[0])]] + r.extend([p[j] for j in range(comp[i], comp[i + 1])] + for i in range(len(comp) - 1)) r.append([p[j] for j in range(comp[-1], len(p))]) r.reverse() return self.element_class(self, r) diff --git a/src/sage/combinat/rsk.py b/src/sage/combinat/rsk.py index 5e276d5ebcf..1fa0ba62b4e 100644 --- a/src/sage/combinat/rsk.py +++ b/src/sage/combinat/rsk.py @@ -2957,12 +2957,10 @@ def _backward_format_output(self, obj1, obj2, output): if j == 0: df.append([]) if j > 0 and obj1[j] < obj1[j-1]: - for _ in range(obj1[j-1]-obj1[j]): - df.append([]) + df.extend([] for _ in range(obj1[j-1]-obj1[j])) df[-1].append(obj2[j]) if obj1: - for a in range(obj1[-1]-1): - df.append([]) + df.extend([] for a in range(obj1[-1]-1)) # If biword is empty, return a decreasing factorization with 1 factor else: df.append([]) diff --git a/src/sage/combinat/shifted_primed_tableau.py b/src/sage/combinat/shifted_primed_tableau.py index 37bbd402c14..6d889425d28 100644 --- a/src/sage/combinat/shifted_primed_tableau.py +++ b/src/sage/combinat/shifted_primed_tableau.py @@ -2716,9 +2716,11 @@ def _add_strip(sub_tab, full_tab, length): if sub_tab and len(sub_tab) < len(full_tab): plat_list.append(min(sub_tab[-1] + primed_strip[-2] - 1, full_tab[len(sub_tab)])) - for row in reversed(range(1, len(sub_tab))): - plat_list.append(min(sub_tab[row-1]+primed_strip[row-1]-1, full_tab[row]) - - sub_tab[row] - primed_strip[row]) + plat_list.extend( + min(sub_tab[row-1] + primed_strip[row-1] - 1, full_tab[row]) + - sub_tab[row] - primed_strip[row] + for row in reversed(range(1, len(sub_tab)))) + if sub_tab: plat_list.append(full_tab[0] - sub_tab[0] - primed_strip[0]) else: diff --git a/src/sage/combinat/skew_partition.py b/src/sage/combinat/skew_partition.py index bee333dc9a5..aad38f9afbf 100644 --- a/src/sage/combinat/skew_partition.py +++ b/src/sage/combinat/skew_partition.py @@ -1032,12 +1032,9 @@ def cells(self): """ outer = self.outer() inner = self.inner()[:] - inner += [0]*(len(outer)-len(inner)) - res = [] - for i in range(len(outer)): - for j in range(inner[i], outer[i]): - res.append( (i,j) ) - return res + inner += [0] * (len(outer) - len(inner)) + return [(i, j) for i, outi in enumerate(outer) + for j in range(inner[i], outi)] def to_list(self): """ @@ -1148,15 +1145,13 @@ def rows_intersection_set(self): sage: skp.rows_intersection_set() == cells True """ - res = [] outer = self.outer() inner = self.inner() - inner += [0] * int(len(outer)-len(inner)) + inner += [0] * (len(outer) - len(inner)) - for i in range(len(outer)): - for j in range(outer[i]): - if outer[i] != inner[i]: - res.append((i,j)) + res = [(i, j) for i, outi in enumerate(outer) + for j in range(outi) + if outi != inner[i]] return Set(res) def columns_intersection_set(self): @@ -1238,7 +1233,7 @@ def jacobi_trudi(self): h = SymmetricFunctions(QQ).homogeneous() H = MatrixSpace(h, nn) - q = q + [0]*int(nn-len(q)) + q = q + [0] * (nn - len(q)) m = [] for i in range(1,nn+1): row = [] diff --git a/src/sage/combinat/skew_tableau.py b/src/sage/combinat/skew_tableau.py index ca57594ed71..44189013d5c 100644 --- a/src/sage/combinat/skew_tableau.py +++ b/src/sage/combinat/skew_tableau.py @@ -1172,10 +1172,10 @@ def row_stabilizer(self): # tableau, by including the identity permutation on the set [1..k]. k = self.size() gens = [list(range(1, k + 1))] - for row in self: - for j in range(len(row) - 1): - if row[j] is not None: - gens.append((row[j], row[j + 1])) + gens.extend((row[j], row[j + 1]) + for row in self + for j in range(len(row) - 1) + if row[j] is not None) return PermutationGroup(gens) def column_stabilizer(self): @@ -1777,12 +1777,10 @@ def cells(self): sage: s.cells() [(0, 1), (0, 2), (1, 0), (2, 0)] """ - res = [] - for i in range(len(self)): - for j in range(len(self[i])): - if self[i][j] is not None: - res.append((i, j)) - return res + return [(i, j) + for i, selfi in enumerate(self) + for j in range(len(selfi)) + if selfi[j] is not None] def cells_containing(self, i): r""" @@ -1950,12 +1948,11 @@ def from_expr(self, expr): sage: SkewTableaux().from_expr([[1,1],[[5],[3,4],[1,2]]]) [[None, 1, 2], [None, 3, 4], [5]] """ - skp = [] outer = expr[1] inner = expr[0] + [0] * (len(outer) - len(expr[0])) - for i in range(len(outer)): - skp.append([None] * (inner[i]) + outer[-(i + 1)]) + skp = [[None] * (inner[i]) + outer[-(i + 1)] + for i in range(len(outer))] return self.element_class(self, skp) diff --git a/src/sage/combinat/specht_module.py b/src/sage/combinat/specht_module.py index 0114a8f191b..1af53083f89 100644 --- a/src/sage/combinat/specht_module.py +++ b/src/sage/combinat/specht_module.py @@ -1146,18 +1146,12 @@ def _to_diagram(D): if isinstance(D, Diagram): return D if D in _Partitions: - D = _Partitions(D).cells() - elif D in SkewPartitions(): - D = SkewPartitions()(D).cells() - elif D in IntegerVectors(): - cells = [] - for i, row in enumerate(D): - for j in range(row): - cells.append((i, j)) - D = cells - else: - D = [tuple(cell) for cell in D] - return D + return _Partitions(D).cells() + if D in SkewPartitions(): + return SkewPartitions()(D).cells() + if D in IntegerVectors(): + return [(i, j) for i, row in enumerate(D) for j in range(row)] + return [tuple(cell) for cell in D] def specht_module_spanning_set(D, SGA=None): diff --git a/src/sage/combinat/symmetric_group_algebra.py b/src/sage/combinat/symmetric_group_algebra.py index b9ea545cd60..47820fc23a5 100644 --- a/src/sage/combinat/symmetric_group_algebra.py +++ b/src/sage/combinat/symmetric_group_algebra.py @@ -1043,10 +1043,8 @@ def central_orthogonal_idempotents(self): - :meth:`central_orthogonal_idempotent` """ - out = [] - for key in sorted(self._blocks_dictionary, reverse=True): - out.append(self.central_orthogonal_idempotent(key)) - return out + return [self.central_orthogonal_idempotent(key) + for key in sorted(self._blocks_dictionary, reverse=True)] def central_orthogonal_idempotent(self, la, block=True): r""" @@ -2016,9 +2014,9 @@ def seminormal_basis(self, mult='l2r'): basis = [] for part in Partitions_n(self.n): stp = StandardTableaux_shape(part) - for t1 in stp: - for t2 in stp: - basis.append(self.epsilon_ik(t1, t2, mult=mult)) + basis.extend(self.epsilon_ik(t1, t2, mult=mult) + for t1 in stp + for t2 in stp) return basis def dft(self, form=None, mult='l2r'): diff --git a/src/sage/combinat/tableau.py b/src/sage/combinat/tableau.py index 19f9033fcea..80e3391b279 100644 --- a/src/sage/combinat/tableau.py +++ b/src/sage/combinat/tableau.py @@ -1148,12 +1148,10 @@ def descents(self): sage: Tableau( [[1,2,3],[4,5]] ).descents() [(1, 0), (1, 1)] """ - descents = [] - for i in range(1, len(self)): - for j in range(len(self[i])): - if self[i][j] > self[i-1][j]: - descents.append((i, j)) - return descents + return [(i, j) + for i in range(1, len(self)) + for j, selfij in enumerate(self[i]) + if selfij > self[i-1][j]] def major_index(self): """ @@ -1214,15 +1212,15 @@ def inversions(self): for j, entry in enumerate(row): # c is in position (i,j) # find the d that satisfy condition 1 - for k in range(j+1, len(row)): - if entry > row[k]: - inversions.append(((i, j), (i, k))) + inversions.extend(((i, j), (i, k)) + for k in range(j + 1, len(row)) + if entry > row[k]) # find the d that satisfy condition 2 if i == 0: continue - for k in range(j): - if entry > previous_row[k]: - inversions.append(((i, j), (i-1, k))) + inversions.extend(((i, j), (i - 1, k)) + for k in range(j) + if entry > previous_row[k]) previous_row = row return inversions diff --git a/src/sage/combinat/tableau_tuple.py b/src/sage/combinat/tableau_tuple.py index a24ac5ca809..fd847c4ad1e 100644 --- a/src/sage/combinat/tableau_tuple.py +++ b/src/sage/combinat/tableau_tuple.py @@ -1084,10 +1084,8 @@ def row_stabilizer(self): # tableau, by including the identity permutation on the set [1..n]. n = max(self.entries()) gens = [list(range(1, n + 1))] - for t in self: - for i in range(len(t)): - for j in range(len(t[i]) - 1): - gens.append((t[i][j], t[i][j + 1])) + gens.extend((ti[j], ti[j + 1]) for t in self + for ti in t for j in range(len(ti) - 1)) return PermutationGroup(gens) def column_stabilizer(self): @@ -2644,11 +2642,10 @@ def an_element(self): ([[1, 2]], [], []) """ if self.size() == 0: - return self.element_class(self, [[] for _ in range(self.level())]) + return self.element_class(self, [[]] * self.level()) tab = [[list(range(1, self.size() + 1))]] - for _ in range(self.level() - 1): - tab.append([]) + tab.extend([] for _ in range(self.level() - 1)) return self.element_class(self, tab)