Skip to content

Commit c92c540

Browse files
author
Release Manager
committed
gh-41149: fixing a few badly written loops as these are creating a list inside just to loop over ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #41149 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, gmou3
2 parents 22f9162 + cff51df commit c92c540

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

src/sage/graphs/strongly_regular_db.pyx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,16 +2492,17 @@ def strongly_regular_from_two_intersection_set(M):
24922492
M = [list(p) for p in M]
24932493
24942494
# For every point in F_q^{k+1} not on the hyperplane of M
2495-
for u in [tuple(x) for x in product(K,repeat=k)]:
2495+
for x in product(K, repeat=k):
2496+
u = tuple(x)
24962497
# For every v point of M
24972498
for v in M:
24982499
# u is adjacent with all vertices on a uv line.
24992500
g.add_edges([[u, tuple([u[i] + qq*v[i] for i in range(k)])]
25002501
for qq in K if not qq == K.zero()])
25012502
g.relabel()
2502-
e = QQ((1,k))
2503+
e = QQ((1, k))
25032504
qq = g.n_vertices()**e
2504-
g.name('two-intersection set in PG('+str(k)+','+str(qq)+')')
2505+
g.name(f'two-intersection set in PG({k},{qq})')
25052506
return g
25062507
25072508

src/sage/modules/fp_graded/module.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,12 @@ def __classcall__(cls, arg0, generator_degrees=None, relations=(), names=None):
175175

176176
# Use the coefficients given for the relations and make module elements
177177
# from them. Filter out the zero elements, as they are redundant.
178-
rels = [v for v in [generator_module(r) for r in relations] if not v.is_zero()]
178+
rels = [v for r in relations
179+
if not (v := generator_module(r)).is_zero()]
179180

180181
# The free module for the relations of the module.
181-
relations_module = arg0.free_graded_module(tuple([r.degree() for r in rels]))
182+
relations_module = arg0.free_graded_module(tuple([r.degree()
183+
for r in rels]))
182184

183185
# The module we want to model is the cokernel of the following morphism
184186
j = Hom(relations_module, generator_module)(rels)

src/sage/plot/animate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ def _combine_kwds(self, *kwds_tuple):
281281
new_kwds.update(kwds)
282282

283283
for name in ['xmin', 'xmax', 'ymin', 'ymax']:
284-
values = [v for v in [kwds.get(name, None) for kwds in kwds_tuple] if v is not None]
284+
values = [v for kwds in kwds_tuple
285+
if (v := kwds.get(name, None)) is not None]
285286
if values:
286287
new_kwds[name] = getattr(builtins, name[1:])(values)
287288
return new_kwds

src/sage/schemes/elliptic_curves/ell_field.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2594,7 +2594,8 @@ class of curves. If the j-invariant is not unique in the isogeny
25942594
curve_max = 0
25952595

25962596
r = [0] * len(Es) # adjacency matrix row
2597-
for C in [I.codomain() for I in E.isogenies_prime_degree(l)]:
2597+
for I in E.isogenies_prime_degree(l):
2598+
C = I.codomain()
25982599
j = next((k for k, F in enumerate(Es) if C.is_isomorphic(F)),
25992600
-1) # index of curve isomorphic to codomain of isogeny
26002601
if j >= 0:

src/sage/topology/simplicial_complex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,10 +1763,10 @@ def is_pseudomanifold(self) -> bool:
17631763
if d == 0:
17641764
return len(self.facets()) == 2
17651765
F = self.facets()
1766-
X = self.faces()[d-1]
1766+
X = self.faces()[d - 1]
17671767
# is each (d-1)-simplex is the face of exactly two facets?
17681768
for s in X:
1769-
if len([a for a in [s.is_face(f) for f in F] if a]) != 2:
1769+
if len([1 for f in F if s.is_face(f)]) != 2:
17701770
return False
17711771
# construct a graph with one vertex for each facet, one edge
17721772
# when two facets intersect in a (d-1)-simplex, and see

src/sage/topology/simplicial_set_examples.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,10 @@ def simplicial_data_from_kenzo_output(filename) -> dict:
683683
else:
684684
simplex_string = data[start:end].strip()
685685

686-
for s in [_.strip() for _ in simplex_string.split('Simplex : ')]:
686+
for ns in simplex_string.split('Simplex : '):
687+
s = ns.strip()
687688
if s:
688-
name, face_str = (_.strip() for _ in s.split('Faces : '))
689+
name, face_str = (nf.strip() for nf in s.split('Faces : '))
689690
face_str = face_str.strip('()')
690691
face_str = face_str.split('<AbSm ')
691692
faces = []

0 commit comments

Comments
 (0)