diff --git a/src/sage/categories/crystals.py b/src/sage/categories/crystals.py index f19a7d963ee..cc2b5042969 100644 --- a/src/sage/categories/crystals.py +++ b/src/sage/categories/crystals.py @@ -16,12 +16,11 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** from __future__ import print_function from builtins import zip -from six import itervalues from sage.misc.cachefunc import cached_method from sage.misc.abstract_method import abstract_method @@ -789,7 +788,7 @@ def crystal_morphism(self, on_gens, codomain=None, codomain = on_gens[0].parent() elif isinstance(on_gens, dict): if on_gens: - codomain = next(itervalues(on_gens)).parent() + codomain = next(iter(on_gens.values())).parent() else: for x in self.module_generators: y = on_gens(x) diff --git a/src/sage/combinat/alternating_sign_matrix.py b/src/sage/combinat/alternating_sign_matrix.py index 9ff0b58199e..1489cc7221c 100644 --- a/src/sage/combinat/alternating_sign_matrix.py +++ b/src/sage/combinat/alternating_sign_matrix.py @@ -32,7 +32,7 @@ # **************************************************************************** from __future__ import division from six.moves import range, zip -from six import itervalues, add_metaclass +from six import add_metaclass import copy from sage.misc.classcall_metaclass import ClasscallMetaclass @@ -1495,7 +1495,7 @@ def _lattice_initializer(self): """ mts, rels = MonotoneTriangles(self._n)._lattice_initializer() bij = {t: self.from_monotone_triangle(t) for t in mts} - return (itervalues(bij), [(bij[a], bij[b]) for (a, b) in rels]) + return (bij.values(), [(bij[a], bij[b]) for (a, b) in rels]) def cover_relations(self): r""" diff --git a/src/sage/combinat/growth.py b/src/sage/combinat/growth.py index 4feb5b52b3c..141fe345d4b 100644 --- a/src/sage/combinat/growth.py +++ b/src/sage/combinat/growth.py @@ -1402,8 +1402,7 @@ def _process_filling_and_shape(self, filling, shape): """ if isinstance(filling, dict): try: - from six import itervalues - v = next(itervalues(filling)) + v = next(iter(filling.values())) if isinstance(v, dict): # it is a dict of dicts F = dict() diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 64b08f01ba1..a68d6734f81 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -229,15 +229,13 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** from __future__ import print_function, absolute_import from builtins import zip from six.moves import range -from six import itervalues - from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets @@ -248,7 +246,7 @@ from sage.structure.global_options import GlobalOptions from sage.interfaces.all import gap from sage.rings.all import ZZ, Integer, PolynomialRing -from sage.arith.all import factorial +from sage.arith.all import factorial, multinomial from sage.matrix.matrix_space import MatrixSpace from sage.combinat.tools import transitive_ideal from sage.combinat.composition import Composition @@ -5507,8 +5505,8 @@ def cardinality(self): sage: Permutations(3,4).cardinality() 0 """ - if self._k <= self.n and self._k >= 0: - return factorial(self.n) // factorial(self.n-self._k) + if 0 <= self._k <= self.n: + return factorial(self.n) // factorial(self.n - self._k) return ZZ.zero() def random_element(self): @@ -5684,11 +5682,8 @@ def cardinality(self): for i in mset_list: d[i] = d.get(i, 0) + 1 - c = factorial(len(lmset)) - for i in itervalues(d): - if i != 1: - c //= factorial(i) - return ZZ(c) + return ZZ(multinomial(d.values())) + class Permutations_set(Permutations): """ diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 65274d8bf4b..e9185d24973 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -90,7 +90,6 @@ # **************************************************************************** from __future__ import print_function -import six from six.moves import range import itertools @@ -393,7 +392,7 @@ def __init__(self, data, domain=None, codomain=None): self._morph = {} dom_alph = list() - for (key,val) in six.iteritems(data): + for key, val in data.items(): dom_alph.append(key) if val in codomain.alphabet(): self._morph[key] = codomain([val]) @@ -474,7 +473,7 @@ def _build_codomain(self, data): Finite words over {0, 1, 2} """ codom_alphabet = set() - for key,val in six.iteritems(data): + for key, val in data.items(): try: it = iter(val) except Exception: @@ -490,7 +489,7 @@ def __hash__(self): sage: hash(WordMorphism('a->ab,b->ba')) # random 7211091143079804375 """ - return hash(tuple((k,v) for k,v in six.iteritems(self._morph))) ^ hash(self._codomain) + return hash(tuple((k,v) for k,v in self._morph.items())) ^ hash(self._codomain) def __eq__(self, other): r""" @@ -603,7 +602,8 @@ def __str__(self): sage: str(s) 'a->ab, b->ba' """ - L = [str(lettre) + '->' + image.string_rep() for lettre,image in six.iteritems(self._morph)] + L = [str(lettre) + '->' + image.string_rep() + for lettre, image in self._morph.items()] return ', '.join(sorted(L)) def __call__(self, w, order=1, datatype=None): @@ -977,7 +977,7 @@ def __mul__(self, other): sage: m * WordMorphism('') WordMorphism: """ - return WordMorphism(dict((key, self(w)) for (key, w) in six.iteritems(other._morph)), codomain=self.codomain()) + return WordMorphism(dict((key, self(w)) for key, w in other._morph.items()), codomain=self.codomain()) def __pow__(self, exp): r""" @@ -1082,7 +1082,7 @@ def extend_by(self, other): raise TypeError("other (=%s) is not a WordMorphism"%other) nv = dict(other._morph) - for k,v in six.iteritems(self._morph): + for k, v in self._morph.items(): nv[k] = v return WordMorphism(nv) @@ -1290,7 +1290,7 @@ def images(self): sage: sorted(WordMorphism('6->ab,y->5,0->asd').images()) [word: 5, word: ab, word: asd] """ - return list(six.itervalues(self._morph)) + return list(self._morph.values()) def reversal(self): r""" @@ -1303,7 +1303,7 @@ def reversal(self): sage: WordMorphism('a->ab,b->a').reversal() WordMorphism: a->ba, b->a """ - return WordMorphism(dict((key, w.reversal()) for (key, w) in six.iteritems(self._morph)),codomain=self._codomain) + return WordMorphism(dict((key, w.reversal()) for (key, w) in self._morph.items()),codomain=self._codomain) def is_empty(self): r""" @@ -2186,7 +2186,7 @@ def conjugate(self, pos): sage: m.conjugate(2) WordMorphism: a->cdeab, b->zxy """ - return WordMorphism(dict((key, w.conjugate(pos)) for (key, w) in six.iteritems(self._morph))) + return WordMorphism(dict((key, w.conjugate(pos)) for (key, w) in self._morph.items())) def has_left_conjugate(self): r""" diff --git a/src/sage/data_structures/mutable_poset.py b/src/sage/data_structures/mutable_poset.py index 530b423bb53..6df1357c03c 100644 --- a/src/sage/data_structures/mutable_poset.py +++ b/src/sage/data_structures/mutable_poset.py @@ -150,8 +150,6 @@ # **************************************************************************** from __future__ import print_function -from six import itervalues - from sage.structure.sage_object import SageObject @@ -1690,7 +1688,7 @@ def _copy_shells_(self, other, mapping): self._null_ = other._null_._copy_all_linked_(memo, self, mapping) self._oo_ = memo[id(other._oo_)] self._shells_ = {f.key: f for f in iter(memo[id(e)] for e in - itervalues(other._shells_))} + other._shells_.values())} def copy(self, mapping=None): r""" @@ -1771,7 +1769,7 @@ def shells(self, include_special=False): """ if include_special: yield self.null - for e in itervalues(self._shells_): + for e in self._shells_.values(): yield e if include_special: yield self.oo diff --git a/src/sage/databases/conway.py b/src/sage/databases/conway.py index b2a984628c3..a5a96f64059 100644 --- a/src/sage/databases/conway.py +++ b/src/sage/databases/conway.py @@ -19,7 +19,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from six import itervalues, iteritems +from six import iteritems from six.moves import cPickle as pickle import collections @@ -168,7 +168,7 @@ def __len__(self): return self._len except AttributeError: pass - self._len = sum(len(a) for a in itervalues(self._store)) + self._len = sum(len(a) for a in self._store.values()) return self._len def __iter__(self): diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 6450e9574ef..2d8a0b7dd48 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -6975,7 +6975,7 @@ def cores(self, k=None, with_labels=False): if with_labels: return core else: - return list(six.itervalues(core)) + return list(core.values()) @doc_index("Leftovers") def modular_decomposition(self, algorithm='habib'): diff --git a/src/sage/knots/link.py b/src/sage/knots/link.py index 36ddf4df387..eda927fb177 100644 --- a/src/sage/knots/link.py +++ b/src/sage/knots/link.py @@ -48,7 +48,6 @@ # **************************************************************************** from __future__ import division -import six from six.moves import range from sage.matrix.constructor import matrix @@ -1340,7 +1339,7 @@ def pd_code(self): else: crossing_dic = {} - pd = list(six.itervalues(crossing_dic)) + pd = list(crossing_dic.values()) self._pd_code = pd return self._pd_code diff --git a/src/sage/matroids/constructor.py b/src/sage/matroids/constructor.py index 07e365e0254..fede3652de5 100644 --- a/src/sage/matroids/constructor.py +++ b/src/sage/matroids/constructor.py @@ -97,13 +97,11 @@ # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import -from six import itervalues - from itertools import combinations from sage.matrix.constructor import Matrix from sage.graphs.all import Graph @@ -917,7 +915,7 @@ def revlex_sort_key(s): if groundset is None: groundset = set() - for X in itervalues(CC): + for X in CC.values(): for Y in X: groundset.update(Y) diff --git a/src/sage/misc/sage_input.py b/src/sage/misc/sage_input.py index b811e98652e..3b1b978d37b 100644 --- a/src/sage/misc/sage_input.py +++ b/src/sage/misc/sage_input.py @@ -174,7 +174,7 @@ from __future__ import print_function, absolute_import -from six import itervalues, iteritems, integer_types, string_types +from six import iteritems, integer_types, string_types def sage_input(x, preparse=True, verify=False, allow_locals=False): @@ -1915,7 +1915,7 @@ def _sie_referenced(self): """ refs = self._sie_args[:] refs.append(self._sie_func) - refs.extend(itervalues(self._sie_kwargs)) + refs.extend(self._sie_kwargs.values()) return refs def _sie_format(self, sif): diff --git a/src/sage/modular/pollack_stevens/manin_map.py b/src/sage/modular/pollack_stevens/manin_map.py index 36ea54103c2..e5118e89d7a 100644 --- a/src/sage/modular/pollack_stevens/manin_map.py +++ b/src/sage/modular/pollack_stevens/manin_map.py @@ -43,7 +43,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import print_function, absolute_import -from six import itervalues, iteritems +from six import iteritems from six.moves import range from sage.rings.continued_fraction import convergents @@ -712,7 +712,7 @@ def normalize(self): (1 + O(11^2), 2 + O(11)) """ sd = self._dict - for val in itervalues(sd): + for val in sd.values(): val.normalize() return self diff --git a/src/sage/modules/multi_filtered_vector_space.py b/src/sage/modules/multi_filtered_vector_space.py index fd69bad8860..e7777d1b92a 100644 --- a/src/sage/modules/multi_filtered_vector_space.py +++ b/src/sage/modules/multi_filtered_vector_space.py @@ -38,7 +38,7 @@ # the License, or (at your option) any later version. # https://www.gnu.org/licenses/ # **************************************************************************** -from six import iteritems, itervalues +from six import iteritems from sage.rings.all import QQ, ZZ, Integer from sage.rings.infinity import infinity, minus_infinity @@ -84,11 +84,11 @@ def MultiFilteredVectorSpace(arg, base_ring=None, check=True): base_ring = QQ else: filtration = dict(arg) - F = next(itervalues(arg)) # the first filtration + F = next(iter(arg.values())) # the first filtration dim = F.dimension() if base_ring is None: base_ring = F.base_ring() - for deg in filtration.keys(): + for deg in filtration: filt = filtration[deg] if filt.base_ring() != base_ring: filt = filt.change_ring(base_ring) diff --git a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py index d404e0a76ba..710cbfba2e7 100644 --- a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py +++ b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py @@ -63,7 +63,6 @@ # https://www.gnu.org/licenses/ # **************************************************************************** from __future__ import print_function, absolute_import -from six import itervalues from six.moves import range from copy import copy @@ -2087,12 +2086,12 @@ def __compute_via_velu(self, xP, yP): a3 = self.__E1.a3() # next iterate over the 2torsion points of the kernel - for Qvalues in itervalues(ker_2tor): + for Qvalues in ker_2tor.values(): (tX, tY) = self.__velu_sum_helper(Qvalues, a1, a3, xP, yP) X = X + tX Y = Y + tY - for Qvalues in itervalues(ker_non2tor): + for Qvalues in ker_non2tor.values(): (tX, tY) = self.__velu_sum_helper(Qvalues, a1, a3, xP, yP) X = X + tX Y = Y + tY @@ -2158,11 +2157,11 @@ def __init_kernel_polynomial_velu(self): psi = poly_ring(1) - for Qvalues in itervalues(self.__kernel_2tor): + for Qvalues in self.__kernel_2tor.values(): xQ = invX(x=Qvalues[0]) psi = psi*(x - xQ) - for Qvalues in itervalues(self.__kernel_non2tor): + for Qvalues in self.__kernel_non2tor.values(): xQ = invX(x=Qvalues[0]) psi = psi*(x - xQ) diff --git a/src/sage/sets/family.py b/src/sage/sets/family.py index 5c2c72fae07..70e18002b2a 100644 --- a/src/sage/sets/family.py +++ b/src/sage/sets/family.py @@ -31,13 +31,12 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ #***************************************************************************** import types from copy import copy from pprint import pformat, saferepr -from six import itervalues from six.moves import range from sage.misc.cachefunc import cached_method @@ -609,7 +608,7 @@ def values(self): if self._keys is not None: return [self._dictionary[key] for key in self._keys] else: - return list(itervalues(self._dictionary)) + return list(self._dictionary.values()) def has_key(self, k): """