summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilfried Luebbe <wluebbe@gmail.com>2014-05-21 21:46:35 +0200
committerWilfried Luebbe <wluebbe@gmail.com>2014-05-21 21:46:35 +0200
commit1d505928a109bdb8cfb358fa6c8ef8df257981d9 (patch)
tree9e9d0e5f5a2e1df56a8cd358ed91c29381e9bedb
parenttrac #16067: fix an error generated by "2to3" (diff)
trac #16067: tidying up the generated patch
- often it was possible to replace list comprehension [x for x in X if f(c)] by a generator expression (x for x in X if f(c)) - sometimes a bit more complicated fixup
-rw-r--r--src/sage/categories/affine_weyl_groups.py2
-rw-r--r--src/sage/combinat/composition.py4
-rw-r--r--src/sage/combinat/core.py3
-rw-r--r--src/sage/combinat/diagram_algebras.py6
-rw-r--r--src/sage/combinat/finite_state_machine.py5
-rw-r--r--src/sage/combinat/free_module.py6
-rw-r--r--src/sage/combinat/k_tableau.py4
-rw-r--r--src/sage/combinat/matrices/latin.py8
-rw-r--r--src/sage/combinat/partition.py8
-rw-r--r--src/sage/combinat/partition_algebra.py6
-rw-r--r--src/sage/combinat/permutation.py2
-rw-r--r--src/sage/combinat/sf/sfa.py10
-rw-r--r--src/sage/combinat/similarity_class_type.py6
-rw-r--r--src/sage/dynamics/flat_surfaces/strata.py3
-rw-r--r--src/sage/geometry/triangulation/point_configuration.py2
-rw-r--r--src/sage/graphs/graph.py2
-rw-r--r--src/sage/homology/homology_group.py4
-rw-r--r--src/sage/homology/simplicial_complex.py4
-rw-r--r--src/sage/rings/polynomial/multi_polynomial_ideal.py2
-rw-r--r--src/sage/schemes/projective/projective_space.py2
-rw-r--r--src/sage/schemes/toric/divisor.py4
21 files changed, 42 insertions, 51 deletions
diff --git a/src/sage/categories/affine_weyl_groups.py b/src/sage/categories/affine_weyl_groups.py
index 63242da..326e425 100644
--- a/src/sage/categories/affine_weyl_groups.py
+++ b/src/sage/categories/affine_weyl_groups.py
@@ -165,7 +165,7 @@ class AffineWeylGroups(Category_singleton):
rword = self.reduced_word()
kp1 = self.parent().n
for i in range(len(rword)):
- for c in [x for x in out.outside_corners() if (x[1]-x[0])%kp1==rword[-i-1]]:
+ for c in (x for x in out.outside_corners() if (x[1]-x[0])%kp1==rword[-i-1]):
out = out.add_cell(c[0],c[1])
return Core(out._list,kp1)
diff --git a/src/sage/combinat/composition.py b/src/sage/combinat/composition.py
index cdd34fc..0d36ecb 100644
--- a/src/sage/combinat/composition.py
+++ b/src/sage/combinat/composition.py
@@ -1180,8 +1180,8 @@ class Composition(CombinatorialObject, Element):
return SkewPartition([[],[]])
return SkewPartition(
- [ [x for x in [l for l in reversed(outer)] if x != 0],
- [x for x in [l for l in reversed(inner)] if x != 0]])
+ [ [x for x in (l for l in reversed(outer)) if x != 0],
+ [x for x in (l for l in reversed(inner)) if x != 0]])
def shuffle_product(self, other, overlap=False):
diff --git a/src/sage/combinat/core.py b/src/sage/combinat/core.py
index 7bf3543..3a2393c 100644
--- a/src/sage/combinat/core.py
+++ b/src/sage/combinat/core.py
@@ -696,8 +696,7 @@ class Cores_size(UniqueRepresentation, Parent):
sage: C.list()
[[3, 1], [2, 1, 1]]
"""
- k_cores = [x for x in Partitions(self.n) if x.is_core(self.k)]
- return [ Core(x, self.k) for x in k_cores ]
+ return [ Core(x, self.k) for x in Partitions(self.n) if x.is_core(self.k) ]
def from_partition(self, part):
r"""
diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py
index e5a16ce..5c98477 100644
--- a/src/sage/combinat/diagram_algebras.py
+++ b/src/sage/combinat/diagram_algebras.py
@@ -1230,8 +1230,7 @@ def is_planar(sp):
for i in range(n):
#Get the positive and negative entries of this part
ap = [x for x in to_consider[i] if x>0]
- an = [x for x in to_consider[i] if x<0]
- an = map(abs, an)
+ an = [abs(x) for x in to_consider[i] if x<0]
#Check if a includes numbers in both the top and bottom rows
if len(ap) > 0 and len(an) > 0:
@@ -1240,8 +1239,7 @@ def is_planar(sp):
continue
#Get the positive and negative entries of this part
bp = [x for x in to_consider[j] if x>0]
- bn = [x for x in to_consider[j] if x<0]
- bn = map(abs, bn)
+ bn = [abs(x) for x in to_consider[j] if x<0]
#Skip the ones that don't involve numbers in both
#the bottom and top rows
diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py
index 0d2d644..f3137d6 100644
--- a/src/sage/combinat/finite_state_machine.py
+++ b/src/sage/combinat/finite_state_machine.py
@@ -7185,10 +7185,7 @@ class Automaton(FiniteStateMachine):
epsilon_successors = {}
direct_epsilon_successors = {}
for state in self.states():
- direct_epsilon_successors[state] = set(map(lambda t:t.to_state,
- [transition for transition in self.transitions(state) if len(transition.word_in) == 0]
- )
- )
+ direct_epsilon_successors[state] = set(transition.to_state for transition in self.transitions(state) if len(transition.word_in) == 0)
epsilon_successors[state] = set([state])
old_count_epsilon_successors = 0
diff --git a/src/sage/combinat/free_module.py b/src/sage/combinat/free_module.py
index d1dfca6..d24ebf9 100644
--- a/src/sage/combinat/free_module.py
+++ b/src/sage/combinat/free_module.py
@@ -450,10 +450,8 @@ class CombinatorialFreeModuleElement(Element):
"""
if have_same_parent(left, right) and left._monomial_coefficients == right._monomial_coefficients:
return 0
- nonzero = lambda mc: mc[1] != 0
- v = sorted(filter(nonzero, left._monomial_coefficients.items()))
- w = list(filter(nonzero, right._monomial_coefficients.items()))
- w.sort()
+ v = sorted(mc for mc in left._monomial_coefficients.items() if mc[1] != 0)
+ w = sorted(mc for mc in right._monomial_coefficients.items() if mc[1] != 0)
return cmp(v, w)
def _add_(self, other):
diff --git a/src/sage/combinat/k_tableau.py b/src/sage/combinat/k_tableau.py
index c684d84..2b867e1 100644
--- a/src/sage/combinat/k_tableau.py
+++ b/src/sage/combinat/k_tableau.py
@@ -1188,7 +1188,7 @@ class WeakTableau_core(WeakTableau_abstract):
"""
R = [v for v in self.shape().to_partition().cells() if self[v[0]][v[1]] < r]
L = [v for v in sw if self[v[0]][v[1]] <= r]
- return max([v[0] for v in L+R])
+ return max(v[0] for v in L+R)
class WeakTableaux_core(WeakTableaux_abstract):
r"""
@@ -2359,7 +2359,7 @@ class StrongTableau(ClonableList):
outer_shape = Core(map(len, T),k+1)
inner_shape = Core([x for x in [row.count(None) for row in T] if x>0], k+1)
Te = [v for row in T for v in row if v is not None]+[0]
- count_marks = tuple([Te.count(-(i+1)) for i in range(-min(Te))])
+ count_marks = tuple(Te.count(-(i+1)) for i in range(-min(Te)))
if not all( v==1 for v in count_marks ):
# if T is not standard -> turn into standard
if weight is not None and tuple(weight)!=count_marks:
diff --git a/src/sage/combinat/matrices/latin.py b/src/sage/combinat/matrices/latin.py
index badea11..607da53 100644
--- a/src/sage/combinat/matrices/latin.py
+++ b/src/sage/combinat/matrices/latin.py
@@ -2533,14 +2533,14 @@ def is_row_and_col_balanced(T1, T2):
"""
for r in range(T1.nrows()):
- val1 = set([x for x in T1.row(r) if x >= 0])
- val2 = set([x for x in T2.row(r) if x >= 0])
+ val1 = set(x for x in T1.row(r) if x >= 0)
+ val2 = set(x for x in T2.row(r) if x >= 0)
if val1 != val2: return False
for c in range(T1.ncols()):
- val1 = set([x for x in T1.column(c) if x >= 0])
- val2 = set([x for x in T2.column(c) if x >= 0])
+ val1 = set(x for x in T1.column(c) if x >= 0)
+ val2 = set(x for x in T2.column(c) if x >= 0)
if val1 != val2: return False
diff --git a/src/sage/combinat/partition.py b/src/sage/combinat/partition.py
index 0a26610..1e9cb06 100644
--- a/src/sage/combinat/partition.py
+++ b/src/sage/combinat/partition.py
@@ -1662,11 +1662,11 @@ class Partition(CombinatorialObject, Element):
mu = self
muconj = mu.conjugate() # Naive implementation
if len(mu) <= len(muconj):
- a = [x for x in [val-i-1 for i, val in enumerate(mu)] if x>=0]
- b = [x for x in [muconj[i]-i-1 for i in range(len(a))] if x>=0]
+ a = [x for x in (val-i-1 for i, val in enumerate(mu)) if x>=0]
+ b = [x for x in (muconj[i]-i-1 for i in range(len(a))) if x>=0]
else:
- b = [x for x in [val-i-1 for i, val in enumerate(muconj)] if x>=0]
- a = [x for x in [mu[i]-i-1 for i in range(len(b))] if x>=0]
+ b = [x for x in (val-i-1 for i, val in enumerate(muconj)) if x>=0]
+ a = [x for x in (mu[i]-i-1 for i in range(len(b))) if x>=0]
return (a,b)
def frobenius_rank(self):
diff --git a/src/sage/combinat/partition_algebra.py b/src/sage/combinat/partition_algebra.py
index 5045901..af02688 100644
--- a/src/sage/combinat/partition_algebra.py
+++ b/src/sage/combinat/partition_algebra.py
@@ -1589,8 +1589,7 @@ def is_planar(sp):
#Get the positive and negative entries of this
#part
ap = [x for x in to_consider[i] if x>0]
- an = [x for x in to_consider[i] if x<0]
- an = map(abs, an)
+ an = [abs(x) for x in to_consider[i] if x<0]
#print a, ap, an
@@ -1602,8 +1601,7 @@ def is_planar(sp):
continue
#Get the positive and negative entries of this part
bp = [x for x in to_consider[j] if x>0]
- bn = [x for x in to_consider[j] if x<0]
- bn = map(abs, bn)
+ bn = [abs(x) for x in to_consider[j] if x<0]
#Skip the ones that don't involve numbers in both
#the bottom and top rows
diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py
index 0337d0a..b2a7c98 100644
--- a/src/sage/combinat/permutation.py
+++ b/src/sage/combinat/permutation.py
@@ -2126,7 +2126,7 @@ class Permutation(CombinatorialObject, Element):
r=[]
for x in self:
if max(r+[0]) > x:
- y = min([z for z in r if z > x])
+ y = min(z for z in r if z > x)
r[r.index(y)] = x
else:
r.append(x)
diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py
index e1d055e..cdaed5f 100644
--- a/src/sage/combinat/sf/sfa.py
+++ b/src/sage/combinat/sf/sfa.py
@@ -4323,9 +4323,9 @@ class SymmetricFunctionAlgebra_generic_Element(CombinatorialFreeModule.Element):
0
"""
if exact:
- res = dict( [x for x in self._monomial_coefficients.items() if sum(x[0]) == d] )
+ res = dict(x for x in self._monomial_coefficients.items() if sum(x[0]) == d)
else:
- res = dict( [x for x in self._monomial_coefficients.items() if sum(x[0]) <= d] )
+ res = dict(x for x in self._monomial_coefficients.items() if sum(x[0]) <= d)
return self.parent()._from_dict(res)
def restrict_partition_lengths(self, l, exact = True):
@@ -4356,9 +4356,9 @@ class SymmetricFunctionAlgebra_generic_Element(CombinatorialFreeModule.Element):
s[1] + s[2, 1] + s[4]
"""
if exact:
- res = dict( [x for x in self._monomial_coefficients.items() if len(x[0]) == l] )
+ res = dict(x for x in self._monomial_coefficients.items() if len(x[0]) == l)
else:
- res = dict( [x for x in self._monomial_coefficients.items() if len(x[0]) <= l] )
+ res = dict(x for x in self._monomial_coefficients.items() if len(x[0]) <= l)
return self.parent()._from_dict(res)
def restrict_parts(self, n):
@@ -4380,7 +4380,7 @@ class SymmetricFunctionAlgebra_generic_Element(CombinatorialFreeModule.Element):
sage: z.restrict_parts(1)
s[1] + s[1, 1, 1]
"""
- res = dict( [x for x in self._monomial_coefficients.items() if _lmax(x[0]) <= n] )
+ res = dict(x for x in self._monomial_coefficients.items() if _lmax(x[0]) <= n)
return self.parent()._from_dict(res)
def expand(self, n, alphabet = 'x'):
diff --git a/src/sage/combinat/similarity_class_type.py b/src/sage/combinat/similarity_class_type.py
index d407783..4691030 100644
--- a/src/sage/combinat/similarity_class_type.py
+++ b/src/sage/combinat/similarity_class_type.py
@@ -628,7 +628,7 @@ class PrimarySimilarityClassTypes(Parent, UniqueRepresentation):
if self._min[0].divides(n):
for par in Partitions(ZZ(n/self._min[0]), starting = self._min[1]):
yield self.element_class(self, self._min[0], par)
- for d in [d for d in divisors(n) if d > self._min[0]]:
+ for d in (d for d in divisors(n) if d > self._min[0]):
for par in Partitions(ZZ(n/d)):
yield self.element_class(self, d, par)
@@ -1176,8 +1176,8 @@ def dictionary_from_generator(gen):
high.
"""
L = list(gen)
- setofkeys = list(set([item[0] for item in L]))
- return dict([(key, sum([entry[1] for entry in [pair for pair in L if pair[0] == key]])) for key in setofkeys])
+ setofkeys = list(set(item[0] for item in L))
+ return dict((key, sum(entry[1] for entry in (pair for pair in L if pair[0] == key))) for key in setofkeys)
def matrix_similarity_classes(n, q = None, invertible = False):
r"""
diff --git a/src/sage/dynamics/flat_surfaces/strata.py b/src/sage/dynamics/flat_surfaces/strata.py
index 0fdf8f7..828ebd2 100644
--- a/src/sage/dynamics/flat_surfaces/strata.py
+++ b/src/sage/dynamics/flat_surfaces/strata.py
@@ -1688,8 +1688,7 @@ class OddConnectedComponentOfAbelianStratum(CCA):
0 1 2 3 4 5 6 7 8 9 10
3 2 5 4 6 8 7 10 9 1 0
"""
- zeroes = [x for x in self._parent._zeroes if x > 0]
- zeroes = map(lambda x: x/2, zeroes)
+ zeroes = [x/2 for x in self._parent._zeroes if x > 0]
n = self._parent._zeroes.count(0)
g = self._parent._genus
diff --git a/src/sage/geometry/triangulation/point_configuration.py b/src/sage/geometry/triangulation/point_configuration.py
index 5be66ba..d81e985 100644
--- a/src/sage/geometry/triangulation/point_configuration.py
+++ b/src/sage/geometry/triangulation/point_configuration.py
@@ -1218,7 +1218,7 @@ class PointConfiguration(UniqueRepresentation, PointConfiguration_base):
d = [ self.face_codimension(i) for i in range(0,self.n_points()) ]
- return tuple( tuple([i for i in range(0,self.n_points()) if d[i]==codim] )
+ return tuple( tuple(i for i in range(0,self.n_points()) if d[i]==codim )
for codim in range(0,self.dim()+1) )
diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py
index 2160447..fcb1311 100644
--- a/src/sage/graphs/graph.py
+++ b/src/sage/graphs/graph.py
@@ -3780,7 +3780,7 @@ class Graph(GenericGraph):
try:
p.solve(log = verbose)
b = p.get_values(b)
- mapping = dict(map(lambda y:y[0],[x for x in b.items() if x[1]]))
+ mapping = dict(x[0] for x in b.items() if x[1])
return mapping
except MIPSolverException:
diff --git a/src/sage/homology/homology_group.py b/src/sage/homology/homology_group.py
index ad6c3ba..7857996 100644
--- a/src/sage/homology/homology_group.py
+++ b/src/sage/homology/homology_group.py
@@ -81,7 +81,7 @@ class HomologyGroup_class(AdditiveAbelianGroup_fixed_gens):
if len(eldv) == 0:
return "0"
rank = len([x for x in eldv if x == 0])
- torsion = sorted([x for x in eldv if x])
+ torsion = sorted(x for x in eldv if x)
if rank > 4:
g = ["Z^%s" % rank]
else:
@@ -117,7 +117,7 @@ class HomologyGroup_class(AdditiveAbelianGroup_fixed_gens):
if len(eldv) == 0:
return "0"
rank = len([x for x in eldv if x == 0])
- torsion = sorted([x for x in eldv if x])
+ torsion = sorted(x for x in eldv if x)
if rank > 4:
g = ["\\ZZ^{{{}}}".format(rank)]
else:
diff --git a/src/sage/homology/simplicial_complex.py b/src/sage/homology/simplicial_complex.py
index e1f2072..438e177 100644
--- a/src/sage/homology/simplicial_complex.py
+++ b/src/sage/homology/simplicial_complex.py
@@ -2620,7 +2620,7 @@ class SimplicialComplex(CategoryObject, GenericCellComplex):
"""
if self._graph is None:
edges = self.n_faces(1)
- vertices = map(min, [f for f in self._facets if f.dimension() == 0])
+ vertices = [min(f) for f in self._facets if f.dimension() == 0]
used_vertices = [] # vertices which are in an edge
d = {}
for e in edges:
@@ -2748,7 +2748,7 @@ class SimplicialComplex(CategoryObject, GenericCellComplex):
Simplicial complex with vertex set (0, 1, 2, 3) and facets {(0, 2, 3), (1, 2, 3), (0, 1)}
"""
# make sure it's a list (it will be a tuple if immutable)
- facets = list([f for f in self._facets if f.dimension()<n])
+ facets = list(f for f in self._facets if f.dimension()<n)
facets.extend(self.n_faces(n))
return SimplicialComplex(facets, is_mutable=self._is_mutable)
diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py
index 6b9b2c6..3177822 100644
--- a/src/sage/rings/polynomial/multi_polynomial_ideal.py
+++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py
@@ -3839,7 +3839,7 @@ class MPolynomialIdeal( MPolynomialIdeal_singular_repr, \
gb = toy_d_basis.d_basis(I, *args, **kwds)
R = self.ring()
- gb = [f for f in [R(f) for f in gb] if f]
+ gb = [f for f in (R(f) for f in gb) if f]
else:
if self.ring().term_order().is_global():
verbose("Warning: falling back to very slow toy implementation.", level=0)
diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py
index c30e98b..0332d65 100644
--- a/src/sage/schemes/projective/projective_space.py
+++ b/src/sage/schemes/projective/projective_space.py
@@ -535,7 +535,7 @@ class ProjectiveSpace_ring(AmbientSpace):
f = monoms[col][:i] + monoms[col][i+1:]
if min([f[j]-e[j] for j in range(n)]) >= 0:
M[row,col] = prod([binomial(f[j],e[j])*pt[j]**(f[j]-e[j]) \
- for j in [k for k in range(n) if f[k]>e[k]]])
+ for j in (k for k in range(n) if f[k]>e[k]) ])
return M
def _morphism(self, *args, **kwds):
diff --git a/src/sage/schemes/toric/divisor.py b/src/sage/schemes/toric/divisor.py
index da50dd9..1d4da7b 100644
--- a/src/sage/schemes/toric/divisor.py
+++ b/src/sage/schemes/toric/divisor.py
@@ -1569,11 +1569,13 @@ class ToricDivisor_generic(Divisor_generic):
fan = self.parent().scheme().fan()
ray_is_negative = [ m*ray + self.coefficient(i) < 0
for i, ray in enumerate(fan.rays()) ]
+
def cone_is_negative(cone): # and non-trivial
if cone.is_trivial():
return False
return all(ray_is_negative[i] for i in cone.ambient_ray_indices())
- negative_cones = list(filter(cone_is_negative, flatten(fan.cones())))
+
+ negative_cones = [cone for cone in flatten(fan.cones()) if cone_is_negative(cone)]
return SimplicialComplex([c.ambient_ray_indices() for c in negative_cones])
def _sheaf_cohomology(self, cplx):