Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 72383e4

Browse files
author
Release Manager
committed
Trac #30774: use iterators inside call of .join for strings
as this avoids to create an intermediate list URL: https://trac.sagemath.org/30774 Reported by: chapoton Ticket author(s): Frédéric Chapoton Reviewer(s): Samuel Lelièvre
2 parents b71767c + 0ededdd commit 72383e4

38 files changed

+141
-140
lines changed

src/sage/algebras/letterplace/free_algebra_letterplace.pyx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,7 @@ cdef class FreeAlgebra_letterplace(Algebra):
596596
raise NotImplementedError("\n Apparently you tried to view the letterplace algebra with\n shift-multiplication as the free algebra over a finitely\n generated free abelian monoid.\n In principle, this is correct, but it is not implemented, yet.")
597597

598598
out.append(self._names[var_ind])
599-
i += (self._degrees[var_ind]-1)
600-
### This was the original implementation, with "monoid hack" but without generator degrees
601-
#s = '.'.join([('%s^%d'%(x,e) if e>1 else x) for x,e in zip(self._names,E[i*ngens:(i+1)*ngens]) if e])
602-
#if s:
603-
# out.append(s)
599+
i += self._degrees[var_ind] - 1
604600
return '*'.join(out)
605601

606602
# Auxiliar methods

src/sage/calculus/calculus.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ def _laplace_latex_(self, *args):
19901990
\mathcal{L}\left(f\left(t\right), t, s\right)
19911991
19921992
"""
1993-
return "\\mathcal{L}\\left(%s\\right)"%(', '.join([latex(x) for x in args]))
1993+
return "\\mathcal{L}\\left(%s\\right)" % (', '.join(latex(x) for x in args))
19941994

19951995
def _inverse_laplace_latex_(self, *args):
19961996
r"""
@@ -2008,7 +2008,8 @@ def _inverse_laplace_latex_(self, *args):
20082008
sage: latex(inverse_laplace(F,s,t))
20092009
\mathcal{L}^{-1}\left(F\left(s\right), s, t\right)
20102010
"""
2011-
return "\\mathcal{L}^{-1}\\left(%s\\right)"%(', '.join([latex(x) for x in args]))
2011+
return "\\mathcal{L}^{-1}\\left(%s\\right)" % (', '.join(latex(x) for x in args))
2012+
20122013

20132014
# Return un-evaluated expression as instances of SFunction class
20142015
_laplace = function_factory('laplace', print_latex_func=_laplace_latex_)

src/sage/combinat/abstract_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ def to_hexacode(self):
14081408
raise ValueError("the width of the tree is too large")
14091409
if self.node_number() == 1:
14101410
return "0"
1411-
return "".join(["%x" % len(self)] + [u.to_hexacode() for u in self])
1411+
return ("%x" % len(self)) + "".join(u.to_hexacode() for u in self)
14121412

14131413
def tree_factorial(self):
14141414
r"""

src/sage/crypto/block_cipher/miniaes.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,13 +1655,14 @@ def GF_to_binary(self, G):
16551655
elif isinstance(G, list):
16561656
if len(G) == 0:
16571657
raise ValueError("input G must be an element of GF(16), a list of elements of GF(16), or a matrix over GF(16)")
1658-
S = "".join([str(self._GF_to_bin[g]) for g in G])
1658+
S = "".join(str(self._GF_to_bin[g]) for g in G)
16591659
return B(S)
16601660
# G is a matrix over GF(16)
16611661
elif isinstance(G, Matrix_dense):
16621662
if not (G.base_ring() is K):
16631663
raise TypeError("input G must be an element of GF(16), a list of elements of GF(16), or a matrix over GF(16)")
1664-
S = "".join([str(self._GF_to_bin[G[i][j]]) for i in range(G.nrows()) for j in range(G.ncols())])
1664+
S = "".join(str(self._GF_to_bin[G[i][j]])
1665+
for i in range(G.nrows()) for j in range(G.ncols()))
16651666
return B(S)
16661667
# the type of G doesn't match the supported types
16671668
else:
@@ -2057,7 +2058,7 @@ def integer_to_binary(self, N):
20572058
bin = BinaryStrings()
20582059
# Here, we assume that each element of the list is an integer n
20592060
# such that 0 <= n <= 15. An error will be raised if otherwise.
2060-
b = "".join([str(self._int_to_bin[n]) for n in N])
2061+
b = "".join(str(self._int_to_bin[n]) for n in N)
20612062
return bin(b)
20622063
elif isinstance(N, Integer):
20632064
# Here, we assume that N is an integer such that 0 <= n <= 15.

src/sage/doctest/control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ def sort_sources(self):
862862
....: DC.stats[source.basename] = {'walltime': 0.1*(i+1)}
863863
sage: DC.sort_sources()
864864
Sorting sources by runtime so that slower doctests are run first....
865-
sage: print("\n".join([source.basename for source in DC.sources]))
865+
sage: print("\n".join(source.basename for source in DC.sources))
866866
sage.doctest.util
867867
sage.doctest.test
868868
sage.doctest.sources

src/sage/doctest/sources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,17 +823,17 @@ def _test_enough_doctests(self, check_extras=True, verbose=True):
823823
else:
824824
print("There are %s tests in %s that are shifted by %s" % (len(shortfall), self.path, dif))
825825
if verbose:
826-
print(" The correct line numbers are %s" % (", ".join([str(n) for n in shortfall])))
826+
print(" The correct line numbers are %s" % (", ".join(str(n) for n in shortfall)))
827827
return
828828
elif len(actual) < len(expected):
829829
print("There are %s tests in %s that are not being run" % (len(expected) - len(actual), self.path))
830830
elif check_extras:
831831
print("There are %s unexpected tests being run in %s" % (len(actual) - len(expected), self.path))
832832
if verbose:
833833
if shortfall:
834-
print(" Tests on lines %s are not run" % (", ".join([str(n) for n in shortfall])))
834+
print(" Tests on lines %s are not run" % (", ".join(str(n) for n in shortfall)))
835835
if check_extras and extras:
836-
print(" Tests on lines %s seem extraneous" % (", ".join([str(n) for n in extras])))
836+
print(" Tests on lines %s seem extraneous" % (", ".join(str(n) for n in extras)))
837837

838838

839839
class SourceLanguage:

src/sage/geometry/point_collection.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ cdef class PointCollection(SageObject):
563563
for i, coordinate in enumerate(point):
564564
widths[i] = max(widths[i], len(coordinate))
565565
format += ",".join("{{:>{}}}".format(width) for width in widths)
566-
r = ",\n".join([format.format(head, *point)
567-
for head, point in zip(heads, r)])
566+
r = ",\n".join(format.format(head, *point)
567+
for head, point in zip(heads, r))
568568
elif _output_format == "tuple":
569569
r = tuple(self)
570570
elif _output_format == "matrix":

src/sage/graphs/generic_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ def to_dictionary(self, edge_labels=False, multiple_edges=False):
17361736
9: {4: [None], 6: [None], 7: [None]}}
17371737
"""
17381738

1739-
# Returning the resuls as a dictionary of lists
1739+
# Returning the results as a dictionary of lists
17401740
#
17411741
# dictionary :
17421742
# {vertex : [list of (out-)neighbors]}

src/sage/groups/perm_gps/permgroup_element.pyx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
934934

935935
def _latex_(self):
936936
r"""
937-
Returns a latex representation of this permutation.
937+
Return a latex representation of this permutation.
938938
939939
EXAMPLES::
940940
@@ -947,7 +947,8 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
947947
\left[(\text{\texttt{a}},\text{\texttt{b}})\right]
948948
"""
949949
from sage.misc.latex import latex
950-
return "".join(["(" + ",".join([latex(x) for x in cycle])+")" for cycle in self.cycle_tuples()])
950+
return "".join(("(" + ",".join(latex(x) for x in cycle) + ")")
951+
for cycle in self.cycle_tuples())
951952

952953
def __getitem__(self, i):
953954
"""
@@ -956,10 +957,8 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
956957
957958
INPUT:
958959
959-
960960
- ``i`` - integer
961961
962-
963962
OUTPUT: a permutation group element
964963
965964
EXAMPLES::

src/sage/matroids/matroids_plot_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,10 @@ def geomrep(M1, B1=None, lineorders1=None, pd=None, sp=False):
780780
if M.rank() == 0:
781781
limits = None
782782
loops = L
783-
looptext = ", ".join([str(l) for l in loops])
783+
looptext = ", ".join(str(l) for l in loops)
784784
rectx = -1
785785
recty = -1
786-
rectw = 0.5 + 0.4*len(loops) + 0.5 # controlled based on len(loops)
786+
rectw = 0.5 + 0.4 * len(loops) + 0.5 # controlled based on len(loops)
787787
recth = 0.6
788788
G += polygon2d([[rectx, recty], [rectx, recty+recth],
789789
[rectx+rectw, recty+recth], [rectx+rectw, recty]],

0 commit comments

Comments
 (0)