summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilfried Luebbe <wluebbe@gmail.com>2014-05-20 18:07:13 +0200
committerWilfried Luebbe <wluebbe@gmail.com>2014-05-20 18:07:13 +0200
commite574c6856980b83c05e687c4f8a50119972789c0 (patch)
treea325135e08717955add6e79c4247a870adbd81e0
parentUpdated Sage version to 6.3.beta1 (diff)
trac #16067: changes generated by "2to3 -w -f filter src/sage"
- adapt to the changed semantic of filter() function in Python 3 - mostly replace filter() by list comprehension - a few times wrap filter() by a call to list()
-rw-r--r--src/sage/categories/affine_weyl_groups.py2
-rw-r--r--src/sage/categories/finite_semigroups.py8
-rw-r--r--src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py4
-rw-r--r--src/sage/combinat/composition.py6
-rw-r--r--src/sage/combinat/core.py2
-rw-r--r--src/sage/combinat/crystals/monomial_crystals.py6
-rw-r--r--src/sage/combinat/descent_algebra.py2
-rw-r--r--src/sage/combinat/diagram_algebras.py12
-rw-r--r--src/sage/combinat/dyck_word.py8
-rw-r--r--src/sage/combinat/finite_state_machine.py17
-rw-r--r--src/sage/combinat/free_module.py2
-rw-r--r--src/sage/combinat/k_tableau.py12
-rw-r--r--src/sage/combinat/lyndon_word.py2
-rw-r--r--src/sage/combinat/matrices/latin.py12
-rw-r--r--src/sage/combinat/misc.py2
-rw-r--r--src/sage/combinat/ncsym/ncsym.py4
-rw-r--r--src/sage/combinat/partition.py18
-rw-r--r--src/sage/combinat/partition_algebra.py12
-rw-r--r--src/sage/combinat/permutation.py9
-rw-r--r--src/sage/combinat/ribbon_tableau.py2
-rw-r--r--src/sage/combinat/set_partition.py12
-rw-r--r--src/sage/combinat/sf/classical.py2
-rw-r--r--src/sage/combinat/sf/sfa.py10
-rw-r--r--src/sage/combinat/similarity_class_type.py4
-rw-r--r--src/sage/combinat/skew_partition.py4
-rw-r--r--src/sage/combinat/skew_tableau.py6
-rw-r--r--src/sage/combinat/split_nk.py2
-rw-r--r--src/sage/combinat/subset.py2
-rw-r--r--src/sage/combinat/words/finite_word.py2
-rw-r--r--src/sage/doctest/control.py2
-rw-r--r--src/sage/dynamics/flat_surfaces/strata.py10
-rw-r--r--src/sage/geometry/cone.py2
-rw-r--r--src/sage/geometry/polyhedron/base.py7
-rw-r--r--src/sage/geometry/triangulation/point_configuration.py2
-rw-r--r--src/sage/graphs/base/graph_backends.py2
-rw-r--r--src/sage/graphs/generic_graph.py8
-rw-r--r--src/sage/graphs/graph.py2
-rw-r--r--src/sage/groups/braid.py2
-rw-r--r--src/sage/homology/chain_complex.py9
-rw-r--r--src/sage/homology/delta_complex.py4
-rw-r--r--src/sage/homology/homology_group.py8
-rw-r--r--src/sage/homology/simplicial_complex.py6
-rw-r--r--src/sage/misc/sagedoc.py6
-rw-r--r--src/sage/modular/arithgroup/arithgroup_perm.py2
-rw-r--r--src/sage/modular/arithgroup/tests.py2
-rw-r--r--src/sage/quadratic_forms/quadratic_form__ternary_Tornaria.py6
-rw-r--r--src/sage/rings/number_field/number_field_ideal.py2
-rw-r--r--src/sage/rings/polynomial/multi_polynomial_ideal.py2
-rw-r--r--src/sage/rings/polynomial/toy_buchberger.py3
-rw-r--r--src/sage/rings/polynomial/toy_d_basis.py3
-rw-r--r--src/sage/schemes/generic/algebraic_scheme.py2
-rw-r--r--src/sage/schemes/projective/projective_space.py2
-rw-r--r--src/sage/schemes/toric/chow_group.py4
-rw-r--r--src/sage/schemes/toric/divisor.py2
-rw-r--r--src/sage/schemes/toric/variety.py2
55 files changed, 134 insertions, 154 deletions
diff --git a/src/sage/categories/affine_weyl_groups.py b/src/sage/categories/affine_weyl_groups.py
index 66cb05c..63242da 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 filter( lambda x: (x[1]-x[0])%kp1==rword[-i-1], out.outside_corners()):
+ 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/categories/finite_semigroups.py b/src/sage/categories/finite_semigroups.py
index 9fbaff4..304640c 100644
--- a/src/sage/categories/finite_semigroups.py
+++ b/src/sage/categories/finite_semigroups.py
@@ -216,9 +216,8 @@ class FiniteSemigroups(Category):
sage: sorted(map(sorted, S.j_classes_of_idempotents()))
[['a'], ['ab', 'ba'], ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'], ['ac', 'ca'], ['b'], ['bc', 'cb'], ['c']]
"""
- return filter(lambda l: len(l) > 0,
- map(lambda cl: filter(attrcall('is_idempotent'), cl),
- self.j_classes()))
+ return [l for l in map(lambda cl: list(filter(attrcall('is_idempotent'), cl)),
+ self.j_classes()) if len(l) > 0]
@cached_method
def j_transversal_of_idempotents(self):
@@ -236,8 +235,7 @@ class FiniteSemigroups(Category):
if x.is_idempotent():
return x
return None
- return filter(lambda x: not x is None,
- map(first_idempotent, self.j_classes()))
+ return [x for x in map(first_idempotent, self.j_classes()) if not x is None]
# TODO: compute eJe, where J is the J-class of e
# TODO: construct the action of self on it, as a permutation group
diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py
index cb0f1e8..19f5434 100644
--- a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py
+++ b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py
@@ -1626,9 +1626,9 @@ class QuiverMutationType_Irreducible(QuiverMutationType_abstract,UniqueRepresent
n = i+j
f = Euler_Phi()
if i == j:
- return ( binomial( 2*i,i ) + sum( f(k) * binomial(2*i/k,i/k)**2 for k in filter( lambda k: k in j.divisors(), i.divisors() ) ) / n ) / 4
+ return ( binomial( 2*i,i ) + sum( f(k) * binomial(2*i/k,i/k)**2 for k in [k for k in i.divisors() if k in j.divisors()] ) / n ) / 4
else:
- return sum( f(k) * binomial(2*i/k,i/k) * binomial(2*j/k,j/k) for k in filter( lambda k: k in j.divisors(), i.divisors() ) ) / ( 2 * n )
+ return sum( f(k) * binomial(2*i/k,i/k) * binomial(2*j/k,j/k) for k in [k for k in i.divisors() if k in j.divisors()] ) / ( 2 * n )
# types B and C (finite and affine)
elif self._letter in ['B','C']:
diff --git a/src/sage/combinat/composition.py b/src/sage/combinat/composition.py
index 3f58ba0..cdd34fc 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(
- [ filter(lambda x: x != 0, [l for l in reversed(outer)]),
- filter(lambda x: x != 0, [l for l in reversed(inner)])])
+ [ [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):
@@ -1765,7 +1765,7 @@ class Compositions(Parent, UniqueRepresentation):
if code == [0]:
return []
- L = filter(lambda x: code[x]==1, range(len(code))) #the positions of the letter 1
+ L = [x for x in range(len(code)) if code[x]==1] #the positions of the letter 1
return self.element_class(self, [L[i]-L[i-1] for i in range(1, len(L))] + [len(code)-L[-1]])
# Allows to unpickle old constrained Compositions_constraints objects.
diff --git a/src/sage/combinat/core.py b/src/sage/combinat/core.py
index 2b3926a..7bf3543 100644
--- a/src/sage/combinat/core.py
+++ b/src/sage/combinat/core.py
@@ -696,7 +696,7 @@ class Cores_size(UniqueRepresentation, Parent):
sage: C.list()
[[3, 1], [2, 1, 1]]
"""
- k_cores = filter(lambda x: x.is_core(self.k), Partitions(self.n))
+ 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 ]
def from_partition(self, part):
diff --git a/src/sage/combinat/crystals/monomial_crystals.py b/src/sage/combinat/crystals/monomial_crystals.py
index 4660e2d..e4c454d 100644
--- a/src/sage/combinat/crystals/monomial_crystals.py
+++ b/src/sage/combinat/crystals/monomial_crystals.py
@@ -322,7 +322,7 @@ class NakajimaYMonomial(Element):
continue
else:
d[(i,a)] = 0
- S = sorted(filter(lambda x: x[0][0]==i, d.iteritems()), key=lambda x: x[0][1])
+ S = sorted([x for x in d.iteritems() if x[0][0]==i], key=lambda x: x[0][1])
return max(sum(S[k][1] for k in range(s)) for s in range(1,len(S)+1))
def _ke(self,i):
@@ -354,7 +354,7 @@ class NakajimaYMonomial(Element):
continue
else:
d[(i,a)] = 0
- S = sorted(filter(lambda x: x[0][0]==i, d.iteritems()), key=lambda x: x[0][1])
+ S = sorted([x for x in d.iteritems() if x[0][0]==i], key=lambda x: x[0][1])
for var,exp in S:
sum += exp
if sum == phi:
@@ -390,7 +390,7 @@ class NakajimaYMonomial(Element):
continue
else:
d[(i,a)] = 0
- S = sorted(filter(lambda x: x[0][0]==i, d.iteritems()), key=lambda x: x[0][1])
+ S = sorted([x for x in d.iteritems() if x[0][0]==i], key=lambda x: x[0][1])
sum = 0
phi = self.phi(i)
for var,exp in S:
diff --git a/src/sage/combinat/descent_algebra.py b/src/sage/combinat/descent_algebra.py
index 7027280..d176107 100644
--- a/src/sage/combinat/descent_algebra.py
+++ b/src/sage/combinat/descent_algebra.py
@@ -448,7 +448,7 @@ class DescentAlgebra(Parent, UniqueRepresentation):
"""
IM = IntegerMatrices(list(p), list(q))
P = Compositions(self.realization_of()._n)
- to_composition = lambda m: P( filter(lambda x: x != 0, m.list()) )
+ to_composition = lambda m: P( [x for x in m.list() if x != 0] )
return self.sum_of_monomials(map(to_composition, IM))
@cached_method
diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py
index f835bee..e5a16ce 100644
--- a/src/sage/combinat/diagram_algebras.py
+++ b/src/sage/combinat/diagram_algebras.py
@@ -1224,13 +1224,13 @@ def is_planar(sp):
to_consider = map(list, sp)
#Singletons don't affect planarity
- to_consider = filter(lambda x: len(x) > 1, to_consider)
+ to_consider = [x for x in to_consider if len(x) > 1]
n = len(to_consider)
for i in range(n):
#Get the positive and negative entries of this part
- ap = filter(lambda x: x>0, to_consider[i])
- an = filter(lambda x: x<0, to_consider[i])
+ 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)
#Check if a includes numbers in both the top and bottom rows
@@ -1239,8 +1239,8 @@ def is_planar(sp):
if i == j:
continue
#Get the positive and negative entries of this part
- bp = filter(lambda x: x>0, to_consider[j])
- bn = filter(lambda x: x<0, to_consider[j])
+ 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)
#Skip the ones that don't involve numbers in both
@@ -1517,7 +1517,7 @@ def set_partition_composition(sp1, sp2):
total_removed = 0
for cc in connected_components:
#Remove the vertices that live in the middle two rows
- new_cc = filter(lambda x: not ( (x[0]<0 and x[1] == 1) or (x[0]>0 and x[1]==2)), cc)
+ new_cc = [x for x in cc if not ( (x[0]<0 and x[1] == 1) or (x[0]>0 and x[1]==2))]
if new_cc == []:
if len(cc) > 1:
diff --git a/src/sage/combinat/dyck_word.py b/src/sage/combinat/dyck_word.py
index 4cbf445..b08c7a1 100644
--- a/src/sage/combinat/dyck_word.py
+++ b/src/sage/combinat/dyck_word.py
@@ -932,7 +932,7 @@ class DyckWord(CombinatorialObject, Element):
sage: DyckWord([]).number_of_open_symbols()
0
"""
- return len(filter(lambda x: x == open_symbol, self))
+ return len([x for x in self if x == open_symbol])
size = deprecated_function_alias(13550, number_of_open_symbols)
@@ -952,7 +952,7 @@ class DyckWord(CombinatorialObject, Element):
sage: DyckWord([]).number_of_close_symbols()
0
"""
- return len(filter(lambda x: x == close_symbol, self))
+ return len([x for x in self if x == close_symbol])
def is_complete(self):
r"""
@@ -1488,8 +1488,8 @@ class DyckWord(CombinatorialObject, Element):
else:
close_positions.append(i + 1)
from sage.combinat.tableau import StandardTableau
- return StandardTableau(filter(lambda x: x != [], [open_positions,
- close_positions]))
+ return StandardTableau([x for x in [open_positions,
+ close_positions] if x != []])
@combinatorial_map(name="to binary trees: up step, left tree, down step, right tree")
def to_binary_tree(self, usemap="1L0R"):
diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py
index 090890e..0d2d644 100644
--- a/src/sage/combinat/finite_state_machine.py
+++ b/src/sage/combinat/finite_state_machine.py
@@ -3475,9 +3475,7 @@ class FiniteStateMachine(SageObject):
adjacent = {}
for source in self.iter_states():
for target in self.iter_states():
- transitions = filter(lambda transition: \
- transition.to_state == target,
- source.transitions)
+ transitions = [transition for transition in source.transitions if transition.to_state == target]
adjacent[source, target] = transitions
for ((source, target), transitions) in adjacent.iteritems():
@@ -4971,8 +4969,7 @@ class FiniteStateMachine(SageObject):
memo = {}
def accessible(sf, read):
- trans = filter(lambda x: x.word_in[0] == read,
- self.transitions(sf))
+ trans = [x for x in self.transitions(sf) if x.word_in[0] == read]
return map(lambda x: (deepcopy(x.to_state, memo), x.word_out),
trans)
@@ -5620,8 +5617,7 @@ class FiniteStateMachine(SageObject):
new_word_in, None))
if what == 'output':
- states = filter(lambda s: s.final_word_out,
- self.iter_final_states())
+ states = [s for s in self.iter_final_states() if s.final_word_out]
if not states:
return new
number = 0
@@ -5783,8 +5779,7 @@ class FiniteStateMachine(SageObject):
"""
DG = self.digraph()
condensation = DG.strongly_connected_components_digraph()
- final_labels = filter(lambda v: condensation.out_degree(v) == 0,
- condensation.vertices())
+ final_labels = [v for v in condensation.vertices() if condensation.out_degree(v) == 0]
return [self.induced_sub_finite_state_machine(map(self.state, component))
for component in final_labels]
@@ -7191,9 +7186,7 @@ class Automaton(FiniteStateMachine):
direct_epsilon_successors = {}
for state in self.states():
direct_epsilon_successors[state] = set(map(lambda t:t.to_state,
- filter(lambda transition: len(transition.word_in) == 0,
- self.transitions(state)
- )
+ [transition for transition in self.transitions(state) if len(transition.word_in) == 0]
)
)
epsilon_successors[state] = set([state])
diff --git a/src/sage/combinat/free_module.py b/src/sage/combinat/free_module.py
index 0a90dc2..d1dfca6 100644
--- a/src/sage/combinat/free_module.py
+++ b/src/sage/combinat/free_module.py
@@ -452,7 +452,7 @@ class CombinatorialFreeModuleElement(Element):
return 0
nonzero = lambda mc: mc[1] != 0
v = sorted(filter(nonzero, left._monomial_coefficients.items()))
- w = filter(nonzero, right._monomial_coefficients.items())
+ w = list(filter(nonzero, right._monomial_coefficients.items()))
w.sort()
return cmp(v, w)
diff --git a/src/sage/combinat/k_tableau.py b/src/sage/combinat/k_tableau.py
index 0916f4a..c684d84 100644
--- a/src/sage/combinat/k_tableau.py
+++ b/src/sage/combinat/k_tableau.py
@@ -1186,8 +1186,8 @@ class WeakTableau_core(WeakTableau_abstract):
sage: t._height_of_restricted_subword(s,6)
4
"""
- R = filter(lambda v : self[v[0]][v[1]] < r, self.shape().to_partition().cells())
- L = filter(lambda v: self[v[0]][v[1]] <= r, sw)
+ 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])
class WeakTableaux_core(WeakTableaux_abstract):
@@ -2357,7 +2357,7 @@ class StrongTableau(ClonableList):
if isinstance(T, cls):
return T
outer_shape = Core(map(len, T),k+1)
- inner_shape = Core(filter(lambda x: x>0, [row.count(None) for row in 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))])
if not all( v==1 for v in count_marks ):
@@ -2491,7 +2491,7 @@ class StrongTableau(ClonableList):
"""
T = self.to_standard_list()
size = Core(map(len,T), self.k+1).length()
- inner_size = Core(map(len,filter(lambda y: len(y)>0, map(lambda row: filter(lambda x: x==None, row ), T))),self.k+1).length()
+ inner_size = Core(map(len,[y for y in map(lambda row: [x for x in row if x==None], T) if len(y)>0]),self.k+1).length()
if len(uniq([v for v in flatten(list(T)) if v in ZZ and v<0]))!=size-inner_size:
return False # TT does not have exactly self.size() marked cells
for i in range(len(T)):
@@ -3638,7 +3638,7 @@ class StrongTableau(ClonableList):
[]
"""
rr = sum(self.weight()[:r])
- rest_tab = filter(lambda y: len(y)>0, map(lambda row: filter(lambda x: x==None or abs(x)<=rr, row ), self.to_standard_list()))
+ rest_tab = [y for y in map(lambda row: [x for x in row if x==None or abs(x)<=rr], self.to_standard_list()) if len(y)>0]
new_parent = StrongTableaux( self.k, (Core(map(len, rest_tab), self.k+1), self.inner_shape()), self.weight()[:r] )
return new_parent(rest_tab)
@@ -4481,7 +4481,7 @@ class StrongTableaux(UniqueRepresentation, Parent):
if msh.length()==sh.length()-1:
# if applying t_{j-l,j+1} reduces the size of the shape by 1
valcells = [LL[c[0]][c[1]] for c in SkewPartition([sh.to_partition(),msh.to_partition()]).cells()]
- if all(x!=None for x in valcells) and all(abs(x)==v for x in valcells) and filter( lambda x: x==-v, valcells )==[-v]:
+ if all(x!=None for x in valcells) and all(abs(x)==v for x in valcells) and [x for x in valcells if x==-v]==[-v]:
# if all values are \pm v and exactly one of them is -v
transeq.append([j-l, j+1])
LL = [[LL[a][b] for b in range(len(LL[a])) if (a,b) in msh.to_partition().cells()] for a in range(len(msh.to_partition()))]
diff --git a/src/sage/combinat/lyndon_word.py b/src/sage/combinat/lyndon_word.py
index 2639351..5e297ad 100644
--- a/src/sage/combinat/lyndon_word.py
+++ b/src/sage/combinat/lyndon_word.py
@@ -337,7 +337,7 @@ class LyndonWords_nk(FiniteWords_length_k_over_OrderedAlphabet):
[word: 112, word: 113, word: 122, word: 123, word: 132, word: 133, word: 223, word: 233]
"""
for c in IntegerVectors(self.k, self.n):
- cf = filter(lambda x: x != 0, c)
+ cf = [x for x in c if x != 0]
nonzero_indices = []
for i in range(len(c)):
if c[i] != 0:
diff --git a/src/sage/combinat/matrices/latin.py b/src/sage/combinat/matrices/latin.py
index 69e28c2..badea11 100644
--- a/src/sage/combinat/matrices/latin.py
+++ b/src/sage/combinat/matrices/latin.py
@@ -517,7 +517,7 @@ class LatinSquare:
"""
symbols = uniq(flatten(map(lambda x: list(x), list(self.square))))
- symbols = filter(lambda x: x >= 0, symbols)
+ symbols = [x for x in symbols if x >= 0]
return len(symbols)
@@ -708,7 +708,7 @@ class LatinSquare:
return False
# Every cell must be filled:
- if len(filter(lambda x: x >= 0, self.list())) != self.nrows()*self.ncols():
+ if len([x for x in self.list() if x >= 0]) != self.nrows()*self.ncols():
return False
# By necessity self must be a partial latin square:
@@ -2533,14 +2533,14 @@ def is_row_and_col_balanced(T1, T2):
"""
for r in range(T1.nrows()):
- val1 = set(filter(lambda x: x >= 0, T1.row(r)))
- val2 = set(filter(lambda x: x >= 0, T2.row(r)))
+ 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(filter(lambda x: x >= 0, T1.column(c)))
- val2 = set(filter(lambda x: x >= 0, T2.column(c)))
+ 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/misc.py b/src/sage/combinat/misc.py
index bb8c17c..6aa6c8f 100644
--- a/src/sage/combinat/misc.py
+++ b/src/sage/combinat/misc.py
@@ -384,7 +384,7 @@ def check_integer_list_constraints(l, **kwargs):
filters['inner'] = lambda x: len(x) >= len(inner) and max([inner[i]-x[i] for i in range(len(inner))]) <= 0
for key in kwargs:
- result = filter( filters[key], result )
+ result = list(filter( filters[key], result ))
if singleton:
try:
diff --git a/src/sage/combinat/ncsym/ncsym.py b/src/sage/combinat/ncsym/ncsym.py
index ad3a904..293c8fe 100644
--- a/src/sage/combinat/ncsym/ncsym.py
+++ b/src/sage/combinat/ncsym/ncsym.py
@@ -302,7 +302,7 @@ class SymmetricFunctionsNonCommutingVariables(UniqueRepresentation, Parent):
return False
for p in s:
f = lambda z: z.intersection(p) != Set([])
- if len(filter(f, list(t)) ) != 1:
+ if len(list(filter(f, list(t))) ) != 1:
return False
return True
@@ -1576,7 +1576,7 @@ class SymmetricFunctionsNonCommutingVariables(UniqueRepresentation, Parent):
return False
for p in s:
f = lambda z: z.intersection(p) != Set([])
- if len(filter(f, list(t)) ) != 1:
+ if len(list(filter(f, list(t))) ) != 1:
return False
return True
diff --git a/src/sage/combinat/partition.py b/src/sage/combinat/partition.py
index 3257a11..0a26610 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 = filter(lambda x: x>=0, [val-i-1 for i, val in enumerate(mu)])
- b = filter(lambda x: x>=0, [muconj[i]-i-1 for i in range(len(a))])
+ 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 = filter(lambda x: x>=0, [val-i-1 for i, val in enumerate(muconj)])
- a = filter(lambda x: x>=0, [mu[i]-i-1 for i in range(len(b))])
+ 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):
@@ -3352,7 +3352,7 @@ class Partition(CombinatorialObject, Element):
sage: Partition([3,2,1]).corners_residue(2, 3)
[(0, 2)]
"""
- return filter(lambda x: self.residue(*x, l=l) == i, self.corners())
+ return [x for x in self.corners() if self.residue(*x, l=l) == i]
inside_corners_residue = corners_residue
removable_cells_residue = corners_residue
@@ -3418,7 +3418,7 @@ class Partition(CombinatorialObject, Element):
sage: Partition([3,2,1]).outside_corners_residue(2, 3)
[(2, 1)]
"""
- return filter(lambda x: self.residue(*x, l=l) == i, self.outside_corners())
+ return [x for x in self.outside_corners() if self.residue(*x, l=l) == i]
addable_cells_residue = outside_corners_residue
@@ -3604,7 +3604,7 @@ class Partition(CombinatorialObject, Element):
#Remove the canonical vector
part = [part[i-1]-len(part)+i for i in range(1, len(part)+1)]
#Select the r-core
- return Partition(filter(lambda x: x != 0, part))
+ return Partition([x for x in part if x != 0])
def quotient(self, length):
r"""
@@ -5149,7 +5149,7 @@ class Partitions(UniqueRepresentation, Parent):
k = length*max(len(q) for q in components) + len(core)
# k needs to be large enough. this seems to me like the smallest it can be
v = [core[i]-i for i in range(len(core))] + [ -i for i in range(len(core),k) ]
- w = [ filter(lambda x: (x-i) % length == 0, v) for i in range(1, length+1) ]
+ w = [ [x for x in v if (x-i) % length == 0] for i in range(1, length+1) ]
new_w = []
for i in range(length):
lw = len(w[i])
@@ -6456,7 +6456,7 @@ class PartitionsInBox(Partitions):
new_list += add(element)
l = new_list
- return [self.element_class(self, filter(lambda x: x!=0, p)) for p in l]
+ return [self.element_class(self, [x for x in p if x!=0]) for p in l]
def PartitionsInBox_hw(h, w):
"""
diff --git a/src/sage/combinat/partition_algebra.py b/src/sage/combinat/partition_algebra.py
index e116e9f..5045901 100644
--- a/src/sage/combinat/partition_algebra.py
+++ b/src/sage/combinat/partition_algebra.py
@@ -1582,14 +1582,14 @@ def is_planar(sp):
to_consider = map(list, sp)
#Singletons don't affect planarity
- to_consider = filter(lambda x: len(x) > 1, to_consider)
+ to_consider = [x for x in to_consider if len(x) > 1]
n = len(to_consider)
for i in range(n):
#Get the positive and negative entries of this
#part
- ap = filter(lambda x: x>0, to_consider[i])
- an = filter(lambda x: x<0, to_consider[i])
+ 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)
#print a, ap, an
@@ -1601,8 +1601,8 @@ def is_planar(sp):
if i == j:
continue
#Get the positive and negative entries of this part
- bp = filter(lambda x: x>0, to_consider[j])
- bn = filter(lambda x: x<0, to_consider[j])
+ 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)
#Skip the ones that don't involve numbers in both
@@ -1850,7 +1850,7 @@ def set_partition_composition(sp1, sp2):
total_removed = 0
for cc in connected_components:
#Remove the vertices that live in the middle two rows
- new_cc = filter(lambda x: not ( (x[0]<0 and x[1] == 1) or (x[0]>0 and x[1]==2)), cc)
+ new_cc = [x for x in cc if not ( (x[0]<0 and x[1] == 1) or (x[0]>0 and x[1]==2))]
if new_cc == []:
if len(cc) > 1:
diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py
index 986738b..0337d0a 100644
--- a/src/sage/combinat/permutation.py
+++ b/src/sage/combinat/permutation.py
@@ -1782,8 +1782,7 @@ class Permutation(CombinatorialObject, Element):
"""
if k > len(self):
return []
- return filter( lambda pos: all( pos[i] < pos[i+1] for i in range(k-1) ),
- subword.Subwords(self, k) )
+ return [pos for pos in subword.Subwords(self, k) if all( pos[i] < pos[i+1] for i in range(k-1) )]
def number_of_noninversions(self, k):
r"""
@@ -2127,7 +2126,7 @@ class Permutation(CombinatorialObject, Element):
r=[]
for x in self:
if max(r+[0]) > x:
- y = min(filter(lambda z: z > x, r))
+ y = min([z for z in r if z > x])
r[r.index(y)] = x
else:
r.append(x)
@@ -6352,7 +6351,7 @@ def from_major_code(mc, final_descent=False):
d.reverse()
#a is the list of all positions which are not descents
- a = filter(lambda x: x not in d, range(len(w)))
+ a = [x for x in range(len(w)) if x not in d]
#d_k = -1 -- 0 in the lemma, but -1 due to 0-based indexing
d.append(-1)
@@ -7112,7 +7111,7 @@ class StandardPermutations_avoiding_123(StandardPermutations_avoiding_generic):
m = p[i]
new_p = []
- non_minima = filter(lambda x: x not in minima, range(self.n, 0, -1))
+ non_minima = [x for x in range(self.n, 0, -1) if x not in minima]
a = 0
b = 0
for i in range(self.n):
diff --git a/src/sage/combinat/ribbon_tableau.py b/src/sage/combinat/ribbon_tableau.py
index 0a06859..9549c8e 100644
--- a/src/sage/combinat/ribbon_tableau.py
+++ b/src/sage/combinat/ribbon_tableau.py
@@ -784,7 +784,7 @@ def graph_implementation_rec(skp, weight, length, function):
retire = [ retire[i] - len(partp) + (i+1) for i in range(len(retire))]
if retire[-1] >= 0 and retire == [i for i in reversed(sorted(retire))]:
- retire = Partition(filter(lambda x: x != 0, retire)).conjugate()
+ retire = Partition([x for x in retire if x != 0]).conjugate()
# Cutting branches if the retired partition has a line strictly included into the inner one
append = True
diff --git a/src/sage/combinat/set_partition.py b/src/sage/combinat/set_partition.py
index 12acf7d..dc9aacc 100644
--- a/src/sage/combinat/set_partition.py
+++ b/src/sage/combinat/set_partition.py
@@ -444,7 +444,7 @@ class SetPartition(ClonableArray):
"""
res = Set(list(self))
for p in t:
- inters = Set(filter(lambda x: x.intersection(p) != Set([]), list(res)))
+ inters = Set([x for x in list(res) if x.intersection(p) != Set([])])
res = res.difference(inters).union(_set_union(inters))
return SetPartition(res)
@@ -1132,7 +1132,7 @@ class SetPartitions(Parent, UniqueRepresentation):
for p in s:
f = lambda z: z.intersection(p) != Set([])
- if len(filter(f, list(t)) ) != 1:
+ if len(list(filter(f, list(t))) ) != 1:
return False
return True
@@ -1182,7 +1182,7 @@ class SetPartitions(Parent, UniqueRepresentation):
return False
for p in t:
- L = filter(lambda x: x.issubset(p), list(s))
+ L = [x for x in list(s) if x.issubset(p)]
if sum(len(x) for x in L) != len(p) \
or any(max(L[i]) > min(L[i+1]) for i in range(len(L)-1)):
return False
@@ -1599,7 +1599,7 @@ def inf(s,t):
from sage.misc.superseded import deprecation
deprecation(14140, 'inf(s, t) is deprecated. Use s.inf(t) instead.')
temp = [ss.intersection(ts) for ss in s for ts in t]
- temp = filter(lambda x: x != Set([]), temp)
+ temp = [x for x in temp if x != Set([])]
return Set(temp)
def sup(s,t):
@@ -1620,7 +1620,7 @@ def sup(s,t):
deprecation(14140, 'sup(s, t) is deprecated. Use s.sup(t) instead.')
res = s
for p in t:
- inters = Set(filter(lambda x: x.intersection(p) != Set([]), list(res)))
+ inters = Set([x for x in list(res) if x.intersection(p) != Set([])])
res = res.difference(inters).union(_set_union(inters))
return res
@@ -1661,7 +1661,7 @@ def less(s, t):
return False
for p in s:
f = lambda z: z.intersection(p) != Set([])
- if len(filter(f, list(t)) ) != 1:
+ if len(list(filter(f, list(t))) ) != 1:
return False
return True
diff --git a/src/sage/combinat/sf/classical.py b/src/sage/combinat/sf/classical.py
index bb6a713..6fa1080 100644
--- a/src/sage/combinat/sf/classical.py
+++ b/src/sage/combinat/sf/classical.py
@@ -129,7 +129,7 @@ class SymmetricFunctionAlgebra_classical(sfa.SymmetricFunctionAlgebra_generic):
# Partitions #
##############
if x in sage.combinat.partition.Partitions():
- return eclass(self, {sage.combinat.partition.Partition(filter(lambda x: x!=0, x)): R.one()})
+ return eclass(self, {sage.combinat.partition.Partition([x for x in x if x!=0]): R.one()})
# Todo: discard all of this which is taken care by Sage's coercion
# (up to changes of base ring)
diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py
index 45adade..e1d055e 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( filter( lambda x: sum(x[0]) == d, self._monomial_coefficients.items()) )
+ res = dict( [x for x in self._monomial_coefficients.items() if sum(x[0]) == d] )
else:
- res = dict( filter( lambda x: sum(x[0]) <= d, self._monomial_coefficients.items()) )
+ 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( filter( lambda x: len(x[0]) == l, self._monomial_coefficients.items()) )
+ res = dict( [x for x in self._monomial_coefficients.items() if len(x[0]) == l] )
else:
- res = dict( filter( lambda x: len(x[0]) <= l, self._monomial_coefficients.items()) )
+ 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( filter( lambda x: _lmax(x[0]) <= n, self._monomial_coefficients.items()) )
+ 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 77fdeb0..d407783 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 filter(lambda d: d > self._min[0], divisors(n)):
+ 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)
@@ -1177,7 +1177,7 @@ def dictionary_from_generator(gen):
"""
L = list(gen)
setofkeys = list(set([item[0] for item in L]))
- return dict([(key, sum([entry[1] for entry in filter(lambda pair: pair[0] == key, L)])) for key in setofkeys])
+ 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/combinat/skew_partition.py b/src/sage/combinat/skew_partition.py
index 94cd39e..b1eed9d 100644
--- a/src/sage/combinat/skew_partition.py
+++ b/src/sage/combinat/skew_partition.py
@@ -1388,7 +1388,7 @@ class SkewPartitions(Parent, UniqueRepresentation):
raise ValueError("Incompatible row and column length : %s and %s"%(rowL, colL))
while colL_new != [] and colL_new[-1] == 0:
colL_new.pop()
- return self.element_class(self, [resOut, filter(lambda x:x, resIn)])
+ return self.element_class(self, [resOut, [x for x in resIn if x]])
class SkewPartitions_all(SkewPartitions):
"""
@@ -1760,7 +1760,7 @@ class SkewPartitions_rowlengths(SkewPartitions):
skp1 = map(lambda x: x + i + mm, skp1)
skp1 += [ck]
skp2 = map(lambda x: x + i + mm, skp2)
- skp2 = filter(lambda x: x != 0, skp2)
+ skp2 = [x for x in skp2 if x != 0]
yield SkewPartition([skp1, skp2])
def __iter__(self):
diff --git a/src/sage/combinat/skew_tableau.py b/src/sage/combinat/skew_tableau.py
index c9e59e6..4fba4c5 100644
--- a/src/sage/combinat/skew_tableau.py
+++ b/src/sage/combinat/skew_tableau.py
@@ -252,7 +252,7 @@ class SkewTableau(CombinatorialObject, Element):
sage: SkewTableau([[None,None,None,2,3],[None,1],[None],[2]]).inner_shape()
[3, 1, 1]
"""
- return Partition(filter(lambda x: x != 0, [row.count(None) for row in self]))
+ return Partition([x for x in [row.count(None) for row in self] if x != 0])
def shape(self):
r"""
@@ -302,7 +302,7 @@ class SkewTableau(CombinatorialObject, Element):
sage: SkewTableau([[None, 2], [1, 3]]).size()
3
"""
- return sum([len(filter(lambda x: x is not None,row)) for row in self])
+ return sum([len([x for x in row if x is not None]) for row in self])
def conjugate(self):
"""
@@ -564,7 +564,7 @@ class SkewTableau(CombinatorialObject, Element):
[[None, 1], [1]]
"""
t = self[:]
- return SkewTableau( filter(lambda z: z != [], map(lambda x: filter(lambda y: y is None or y <= n, x), t)) )
+ return SkewTableau( [z for z in map(lambda x: [y for y in x if y is None or y <= n], t) if z != []] )
def restriction_outer_shape(self, n):
"""
diff --git a/src/sage/combinat/split_nk.py b/src/sage/combinat/split_nk.py
index eb378c5..9f38aed 100644
--- a/src/sage/combinat/split_nk.py
+++ b/src/sage/combinat/split_nk.py
@@ -107,7 +107,7 @@ class SplitNK_nk(CombinatorialClass):
"""
range_n = range(self._n)
for kset in choose_nk.ChooseNK(self._n,self._k):
- yield [ kset, filter(lambda x: x not in kset, range_n) ]
+ yield [ kset, [x for x in range_n if x not in kset] ]
def random_element(self):
diff --git a/src/sage/combinat/subset.py b/src/sage/combinat/subset.py
index 13d72a2..24daf05 100644
--- a/src/sage/combinat/subset.py
+++ b/src/sage/combinat/subset.py
@@ -252,7 +252,7 @@ class Subsets_s(CombinatorialClass):
"""
lset = __builtin__.list(self.s)
n = len(self.s)
- return Set(filter(lambda x: rnd.randint(0,1), lset))
+ return Set([x for x in lset if rnd.randint(0,1)])
def rank(self, sub):
"""
diff --git a/src/sage/combinat/words/finite_word.py b/src/sage/combinat/words/finite_word.py
index a622259..645a7ae 100644
--- a/src/sage/combinat/words/finite_word.py
+++ b/src/sage/combinat/words/finite_word.py
@@ -3137,7 +3137,7 @@ exponent %s: the length of the word (%s) times the exponent \
possible = (i for i in xrange(1,n) if n % i == 0)
else:
possible = xrange(1, n)
- return filter(self.has_period, possible)
+ return list(filter(self.has_period, possible))
def longest_common_subword(self,other):
r"""
diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py
index 1a5af8c..2d1717a 100644
--- a/src/sage/doctest/control.py
+++ b/src/sage/doctest/control.py
@@ -584,7 +584,7 @@ class DocTestController(SageObject):
def is_failure(source):
basename = source.basename
return basename not in self.stats or self.stats[basename].get('failed')
- self.sources = filter(is_failure, self.sources)
+ self.sources = list(filter(is_failure, self.sources))
def sort_sources(self):
r"""
diff --git a/src/sage/dynamics/flat_surfaces/strata.py b/src/sage/dynamics/flat_surfaces/strata.py
index f5a9ab4..0fdf8f7 100644
--- a/src/sage/dynamics/flat_surfaces/strata.py
+++ b/src/sage/dynamics/flat_surfaces/strata.py
@@ -799,7 +799,7 @@ class AbelianStratum(SageObject):
self._genus = Integer(self._genus)
- zeroes = sorted(filter(lambda x: x > 0, self._zeroes))
+ zeroes = sorted([x for x in self._zeroes if x > 0])
if self._genus == 1:
self._cc = (HypCCA,)
@@ -825,7 +825,7 @@ class AbelianStratum(SageObject):
else:
self._cc = (HypCCA, OddCCA, EvenCCA)
- elif len(filter(lambda x: x % 2, zeroes)) == 0:
+ elif len([x for x in zeroes if x % 2]) == 0:
# even zeroes [2 l_1, 2 l_2, ..., 2 l_n]
self._cc = (OddCCA, EvenCCA)
@@ -1269,7 +1269,7 @@ class ConnectedComponentOfAbelianStratum(SageObject):
H_c(1, 1, 1, 1)
"""
g = self._parent._genus
- zeroes = filter(lambda x: x > 0, self._parent._zeroes)
+ zeroes = [x for x in self._parent._zeroes if x > 0]
n = self._parent._zeroes.count(0)
l0 = range(0, 4*g-3)
@@ -1610,7 +1610,7 @@ class EvenConnectedComponentOfAbelianStratum(CCA):
sage: p.connected_component()
H_even(4, 4)
"""
- zeroes = filter(lambda x: x > 0, self._parent._zeroes)
+ zeroes = [x for x in self._parent._zeroes if x > 0]
n = self._parent._zeroes.count(0)
g = self._parent._genus
@@ -1688,7 +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 = filter(lambda x: x > 0, self._parent._zeroes)
+ zeroes = [x for x in self._parent._zeroes if x > 0]
zeroes = map(lambda x: x/2, zeroes)
n = self._parent._zeroes.count(0)
diff --git a/src/sage/geometry/cone.py b/src/sage/geometry/cone.py
index ad1447a..6058648 100644
--- a/src/sage/geometry/cone.py
+++ b/src/sage/geometry/cone.py
@@ -3641,7 +3641,7 @@ class ConvexRationalPolyhedralCone(IntegralRayCollection,
return tuple(gens)
gens = list(parallelotope_points(self.rays(), N)) + list(self.rays())
- gens = filter(lambda v: gcd(v) == 1, gens)
+ gens = [v for v in gens if gcd(v) == 1]
return PointCollection(gens, N)
@cached_method
diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py
index c894a88..9ea5448 100644
--- a/src/sage/geometry/polyhedron/base.py
+++ b/src/sage/geometry/polyhedron/base.py
@@ -2256,9 +2256,8 @@ class Polyhedron_base(Element):
[self.vertices().index(q) for q in proj_verts]])
else:
vs = a_face[1][:]
- adj = dict([a[0], filter(lambda p: p in a_face[1], a[1])]
- for a in filter(lambda va: va[0] in a_face[1],
- self.vertex_adjacencies()))
+ adj = dict([a[0], [p for p in a[1] if p in a_face[1]]]
+ for a in [va for va in self.vertex_adjacencies() if va[0] in a_face[1]])
t = vs[0]
vs.remove(t)
ts = adj[t]
@@ -3865,7 +3864,7 @@ class Polyhedron_base(Element):
pass
if self.is_lattice_polytope():
return list(lp.points_pc())
- return filter(lambda p: self.contains(p), lp.points_pc())
+ return [p for p in lp.points_pc() if self.contains(p)]
@cached_method
def bounding_box(self, integral=False):
diff --git a/src/sage/geometry/triangulation/point_configuration.py b/src/sage/geometry/triangulation/point_configuration.py
index 587eae6..5be66ba 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(filter( lambda i: d[i]==codim, range(0,self.n_points())) )
+ 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/base/graph_backends.py b/src/sage/graphs/base/graph_backends.py
index 4a6b717..1b94cfe 100644
--- a/src/sage/graphs/base/graph_backends.py
+++ b/src/sage/graphs/base/graph_backends.py
@@ -839,7 +839,7 @@ class NetworkXGraphBackend(GenericGraphBackend):
vertices = list(vertices)
nones = vertices.count(None)
- vertices = filter(lambda v: v is not None, vertices)
+ vertices = [v for v in vertices if v is not None]
self._nxg.add_nodes_from(vertices)
new_names = []
diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py
index bd0230f..f43b15a 100644
--- a/src/sage/graphs/generic_graph.py
+++ b/src/sage/graphs/generic_graph.py
@@ -5571,11 +5571,9 @@ class GenericGraph(GenericGraph_pyx):
cut = p.get_values(cut)
if self.is_directed():
- return filter(lambda u_v_l: cut[u_v_l[0], u_v_l[1]] == 1,
- self.edge_iterator())
+ return [u_v_l for u_v_l in self.edge_iterator() if cut[u_v_l[0], u_v_l[1]] == 1]
- return filter(lambda u_v_l: cut[R(u_v_l[0], u_v_l[1])] == 1,
- self.edge_iterator())
+ return [u_v_l for u_v_l in self.edge_iterator() if cut[R(u_v_l[0], u_v_l[1])] == 1]
def max_cut(self, value_only=True, use_edge_labels=False, vertices=False, solver=None, verbose=0):
@@ -10207,7 +10205,7 @@ class GenericGraph(GenericGraph_pyx):
else:
filter = lambda v, self: self._backend.degree(v, self._directed)
for v in vertices:
- yield filter(v, self)
+ yield list(filter(v, self))
def degree_sequence(self):
r"""
diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py
index 71e740b..2160447 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],filter(lambda x:x[1], b.items())))
+ mapping = dict(map(lambda y:y[0],[x for x in b.items() if x[1]]))
return mapping
except MIPSolverException:
diff --git a/src/sage/groups/braid.py b/src/sage/groups/braid.py
index 43b933b..00c793e 100644
--- a/src/sage/groups/braid.py
+++ b/src/sage/groups/braid.py
@@ -678,7 +678,7 @@ class Braid(FinitelyPresentedGroupElement):
i += 1
j += 1
i = 0
- form = filter(lambda a: a.length()>0, form)
+ form = [a for a in form if a.length()>0]
while form!=[] and form[0]==Delta:
form.pop(0)
delta = delta-1
diff --git a/src/sage/homology/chain_complex.py b/src/sage/homology/chain_complex.py
index b5140f5..f7716a6 100644
--- a/src/sage/homology/chain_complex.py
+++ b/src/sage/homology/chain_complex.py
@@ -252,7 +252,7 @@ def ChainComplex(data=None, **kwds):
elif isinstance(data, dict): # data is dictionary
data_dict = data
else: # data is list/tuple/iterable
- data_matrices = filter(lambda x: isinstance(x, Matrix), data)
+ data_matrices = [x for x in data if isinstance(x, Matrix)]
if degree != 1:
raise ValueError('degree must be +1 if the data argument is a list or tuple')
if grading_group != ZZ:
@@ -1264,7 +1264,7 @@ class ChainComplex_class(Parent):
all_divs = all_divs[:d_out_nullity]
# divisors equal to 1 produce trivial
# summands, so filter them out
- divisors = filter(lambda x: x != 1, all_divs)
+ divisors = [x for x in all_divs if x != 1]
answer = HomologyGroup(len(divisors), base_ring, divisors)
else:
raise NotImplementedError('only base rings ZZ and fields are supported')
@@ -1300,7 +1300,7 @@ class ChainComplex_class(Parent):
all_divs[i] = N[i][i]
if N[i][i] == 1:
non_triv = non_triv + 1
- divisors = filter(lambda x: x != 1, all_divs)
+ divisors = [x for x in all_divs if x != 1]
gens = (K * P.inverse().submatrix(col=non_triv)).columns()
return divisors, gens
@@ -1546,8 +1546,7 @@ class ChainComplex_class(Parent):
sage: C
Chain complex with at most 2 nonzero terms over Integer Ring
"""
- diffs = filter(lambda mat: mat.nrows() + mat.ncols() > 0,
- self._diff.values())
+ diffs = [mat for mat in self._diff.values() if mat.nrows() + mat.ncols() > 0]
if len(diffs) == 0:
s = 'Trivial chain complex'
else:
diff --git a/src/sage/homology/delta_complex.py b/src/sage/homology/delta_complex.py
index f77713e..c661d42 100644
--- a/src/sage/homology/delta_complex.py
+++ b/src/sage/homology/delta_complex.py
@@ -617,7 +617,7 @@ class DeltaComplex(GenericCellComplex):
empty_simplex = 0
vertices = self.n_cells(0, subcomplex=subcomplex)
old = vertices
- old_real = filter(lambda x: x is not None, old) # get rid of faces not in subcomplex
+ old_real = [x for x in old if x is not None] # get rid of faces not in subcomplex
n = len(old_real)
differentials[0] = matrix(base_ring, empty_simplex, n, n*empty_simplex*[1])
# current is list of simplices in dimension dim
@@ -626,7 +626,7 @@ class DeltaComplex(GenericCellComplex):
# old_real is list of simplices in dimension dim-1, with None filtered out
for dim in range(1,self.dimension()+1):
current = list(self.n_cells(dim, subcomplex=subcomplex))
- current_real = filter(lambda x: x is not None, current)
+ current_real = [x for x in current if x is not None]
i = 0
i_real = 0
translate = {}
diff --git a/src/sage/homology/homology_group.py b/src/sage/homology/homology_group.py
index 711ef7d..ad6c3ba 100644
--- a/src/sage/homology/homology_group.py
+++ b/src/sage/homology/homology_group.py
@@ -80,8 +80,8 @@ class HomologyGroup_class(AdditiveAbelianGroup_fixed_gens):
eldv = self._original_invts
if len(eldv) == 0:
return "0"
- rank = len(filter(lambda x: x == 0, eldv))
- torsion = sorted(filter(lambda x: x, eldv))
+ rank = len([x for x in eldv if x == 0])
+ torsion = sorted([x for x in eldv if x])
if rank > 4:
g = ["Z^%s" % rank]
else:
@@ -116,8 +116,8 @@ class HomologyGroup_class(AdditiveAbelianGroup_fixed_gens):
eldv = self._original_invts
if len(eldv) == 0:
return "0"
- rank = len(filter(lambda x: x == 0, eldv))
- torsion = sorted(filter(lambda x: x, eldv))
+ rank = len([x for x in eldv if x == 0])
+ 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 cfa8e6e..e1f2072 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, filter(lambda f: f.dimension() == 0, self._facets))
+ vertices = map(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(filter(lambda f: f.dimension()<n, self._facets))
+ 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)
@@ -2841,7 +2841,7 @@ class SimplicialComplex(CategoryObject, GenericCellComplex):
if subcomplex in self.__enlarged:
return self.__enlarged[subcomplex]
- faces = filter(lambda x: x not in subcomplex._facets, list(self._facets))
+ faces = [x for x in list(self._facets) if x not in subcomplex._facets]
done = False
new_facets = list(subcomplex._facets)
while not done:
diff --git a/src/sage/misc/sagedoc.py b/src/sage/misc/sagedoc.py
index cc60d09..2f4516e 100644
--- a/src/sage/misc/sagedoc.py
+++ b/src/sage/misc/sagedoc.py
@@ -808,10 +808,8 @@ You can build this with 'sage -docbuild {} html'.""".format(s))
if re.search(string, line, flags)]
for extra in [extra1, extra2, extra3, extra4, extra5]:
if extra:
- match_list = filter(lambda s:
- re.search(extra, s[1],
- re.MULTILINE | flags),
- match_list)
+ match_list = [s for s in match_list if re.search(extra, s[1],
+ re.MULTILINE | flags)]
for num, line in match_list:
results += ':'.join([filename[strip:].lstrip("/"),
str(num+1),
diff --git a/src/sage/modular/arithgroup/arithgroup_perm.py b/src/sage/modular/arithgroup/arithgroup_perm.py
index 0bfa823..07be6e6 100644
--- a/src/sage/modular/arithgroup/arithgroup_perm.py
+++ b/src/sage/modular/arithgroup/arithgroup_perm.py
@@ -388,7 +388,7 @@ def ArithmeticSubgroup_Permutation(
L=(1,2)(3,5,4)
R=(1,2)(3,4,5)
"""
- gens = filter(lambda x: x is not None, [S2,S3,L,R])
+ gens = [x for x in [S2,S3,L,R] if x is not None]
if len(gens) == 0:
S2 = S3 = L = R = ''
elif len(gens) < 2:
diff --git a/src/sage/modular/arithgroup/tests.py b/src/sage/modular/arithgroup/tests.py
index b903518..c29040d 100644
--- a/src/sage/modular/arithgroup/tests.py
+++ b/src/sage/modular/arithgroup/tests.py
@@ -121,7 +121,7 @@ class Test:
while Gamma1(i).index() < index_max:
self.congroups.append(Gamma1(i))
M = Zmod(i)
- U = filter(lambda x: x.is_unit(), M)
+ U = [x for x in M if x.is_unit()]
for j in xrange(1,len(U)-1):
self.congroups.append(GammaH(i,prandom.sample(U,j)))
i += 1
diff --git a/src/sage/quadratic_forms/quadratic_form__ternary_Tornaria.py b/src/sage/quadratic_forms/quadratic_form__ternary_Tornaria.py
index c1a6257..a201d4b 100644
--- a/src/sage/quadratic_forms/quadratic_form__ternary_Tornaria.py
+++ b/src/sage/quadratic_forms/quadratic_form__ternary_Tornaria.py
@@ -317,8 +317,7 @@ def hasse_conductor(self):
10
"""
D = self.disc()
- return prod(filter(lambda p: self.hasse_invariant(p) == -1,
- map(lambda x: x[0], factor(2 * self.level()))))
+ return prod([p for p in map(lambda x: x[0], factor(2 * self.level())) if self.hasse_invariant(p) == -1])
def clifford_invariant(self, p):
"""
@@ -393,8 +392,7 @@ def clifford_conductor(self):
"""
D = self.disc()
- return prod(filter(lambda p: self.clifford_invariant(p) == -1,
- map(lambda x: x[0], factor(2 * self.level()))))
+ return prod([p for p in map(lambda x: x[0], factor(2 * self.level())) if self.clifford_invariant(p) == -1])
### Genus theory
diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py
index 51dadd8..5f7cc40 100644
--- a/src/sage/rings/number_field/number_field_ideal.py
+++ b/src/sage/rings/number_field/number_field_ideal.py
@@ -926,7 +926,7 @@ class NumberFieldIdeal(Ideal_generic):
self.__integral_split = (self, ZZ(1))
else:
factors = self.factor()
- denom_list = filter(lambda p_e: p_e[1] < 0, factors)
+ denom_list = [p_e for p_e in factors if p_e[1] < 0]
denominator = prod([ p.smallest_integer()**(-e)
for (p,e) in denom_list ])
## Get a list of the primes dividing the denominator
diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py
index 5d7f88c..6b9b2c6 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 = filter(lambda f: f,[R(f) for f in gb])
+ 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/rings/polynomial/toy_buchberger.py b/src/sage/rings/polynomial/toy_buchberger.py
index 1fc074f..7c45a25 100644
--- a/src/sage/rings/polynomial/toy_buchberger.py
+++ b/src/sage/rings/polynomial/toy_buchberger.py
@@ -203,8 +203,7 @@ def buchberger(F):
"""
G = set(F.gens())
- B = set(filter(lambda x_y: x_y[0] != x_y[1],
- [(g1, g2) for g1 in G for g2 in G]))
+ B = set([x_y for x_y in [(g1, g2) for g1 in G for g2 in G] if x_y[0] != x_y[1]])
if get_verbose() >= 1:
reductions_to_zero = 0
diff --git a/src/sage/rings/polynomial/toy_d_basis.py b/src/sage/rings/polynomial/toy_d_basis.py
index 91f719d..3fec958 100644
--- a/src/sage/rings/polynomial/toy_d_basis.py
+++ b/src/sage/rings/polynomial/toy_d_basis.py
@@ -212,8 +212,7 @@ def d_basis(F, strat=True):
K = R.base_ring()
G = set(inter_reduction(F.gens()))
- B = set(filter(lambda x_y: x_y[0] != x_y[1],
- [(f1, f2) for f1 in G for f2 in G]))
+ B = set([x_y for x_y in [(f1, f2) for f1 in G for f2 in G] if x_y[0] != x_y[1]])
D = set()
C = set(B)
diff --git a/src/sage/schemes/generic/algebraic_scheme.py b/src/sage/schemes/generic/algebraic_scheme.py
index c431296..886f7b4 100644
--- a/src/sage/schemes/generic/algebraic_scheme.py
+++ b/src/sage/schemes/generic/algebraic_scheme.py
@@ -2392,7 +2392,7 @@ class AlgebraicScheme_subscheme_toric(AlgebraicScheme_subscheme):
polynomials = map(pullback_polynomial, polynomials)
patch_cover = sage.schemes.affine.affine_space.AffineSpace(R)
polynomials = list(I.gens()) + polynomials
- polynomials = filter( lambda x:not x.is_zero(), polynomials)
+ polynomials = [x for x in polynomials if not x.is_zero()]
patch = patch_cover.subscheme(polynomials)
# TODO: If the cone is not smooth, then the coordinate_ring()
diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py
index 5ab5cdc..c30e98b 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 filter(lambda k: f[k]>e[k], range(n))])
+ 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/chow_group.py b/src/sage/schemes/toric/chow_group.py
index efa887d..2f2370b 100644
--- a/src/sage/schemes/toric/chow_group.py
+++ b/src/sage/schemes/toric/chow_group.py
@@ -1180,8 +1180,8 @@ class ChowGroup_degree_class(SageObject):
if len(invariants)==0:
return '0'
- free = filter(lambda x:x==0, invariants)
- tors = filter(lambda x:x> 0, invariants)
+ free = [x for x in invariants if x==0]
+ tors = [x for x in invariants if x> 0]
if self._Chow_group.base_ring()==ZZ:
ring = 'Z'
diff --git a/src/sage/schemes/toric/divisor.py b/src/sage/schemes/toric/divisor.py
index b7a0c66..da50dd9 100644
--- a/src/sage/schemes/toric/divisor.py
+++ b/src/sage/schemes/toric/divisor.py
@@ -1573,7 +1573,7 @@ class ToricDivisor_generic(Divisor_generic):
if cone.is_trivial():
return False
return all(ray_is_negative[i] for i in cone.ambient_ray_indices())
- negative_cones = filter(cone_is_negative, flatten(fan.cones()))
+ negative_cones = list(filter(cone_is_negative, flatten(fan.cones())))
return SimplicialComplex([c.ambient_ray_indices() for c in negative_cones])
def _sheaf_cohomology(self, cplx):
diff --git a/src/sage/schemes/toric/variety.py b/src/sage/schemes/toric/variety.py
index 81d8291..8ea8b19 100644
--- a/src/sage/schemes/toric/variety.py
+++ b/src/sage/schemes/toric/variety.py
@@ -3514,7 +3514,7 @@ class CohomologyClass(QuotientRingElement):
"""
Q = self.parent()
# We iterate over monomials of self.lift()
- p = filter( lambda x: x[1].total_degree() == d, self.lift() )
+ p = [x for x in self.lift() if x[1].total_degree() == d]
if len(p)==0:
return Q.zero()
else: