From 8fe2a8a3f50915dbf1d0cb6c052d0ec4ce33f123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 3 Feb 2017 13:53:27 +0100 Subject: [PATCH] py3: get rid of .iteritems in combinat folder --- src/sage/combinat/combinat.py | 3 +- src/sage/combinat/combinatorial_algebra.py | 11 ++++--- .../combinat/crystals/monomial_crystals.py | 33 ++++++++++--------- src/sage/combinat/designs/block_design.py | 7 ++-- src/sage/combinat/designs/database.py | 5 +-- .../combinat/designs/difference_family.py | 3 +- src/sage/combinat/designs/ext_rep.py | 3 +- .../combinat/designs/incidence_structures.py | 13 ++++---- src/sage/combinat/designs/latin_squares.py | 5 ++- .../combinat/designs/orthogonal_arrays.py | 7 ++-- src/sage/combinat/finite_state_machine.py | 25 +++++++------- src/sage/combinat/free_module.py | 11 ++++--- src/sage/combinat/fully_packed_loop.py | 5 ++- src/sage/combinat/k_tableau.py | 6 +++- src/sage/combinat/ncsf_qsym/qsym.py | 5 ++- src/sage/combinat/partition.py | 3 +- src/sage/combinat/posets/lattices.py | 5 ++- src/sage/combinat/posets/posets.py | 5 +-- .../combinat/root_system/ambient_space.py | 5 ++- .../root_lattice_realization_algebras.py | 5 ++- src/sage/combinat/root_system/type_folded.py | 5 ++- .../combinat/root_system/type_reducible.py | 5 ++- src/sage/combinat/sf/character.py | 5 ++- src/sage/combinat/sf/classical.py | 5 ++- src/sage/combinat/sf/kfpoly.py | 19 ++++++----- src/sage/combinat/sf/monomial.py | 12 ++++--- src/sage/combinat/sf/sfa.py | 18 ++++++---- src/sage/combinat/species/stream.py | 7 ++-- src/sage/combinat/subset.py | 3 +- src/sage/combinat/symmetric_group_algebra.py | 9 ++--- .../symmetric_group_representations.py | 3 +- src/sage/combinat/tiling.py | 13 ++++---- src/sage/combinat/words/morphism.py | 19 ++++++----- src/sage/combinat/words/suffix_trees.py | 3 +- 34 files changed, 183 insertions(+), 108 deletions(-) diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index 8be46df17ff..fd345fc4b33 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -144,6 +144,7 @@ #***************************************************************************** from __future__ import absolute_import +import six from six.moves import range from sage.interfaces.all import maxima @@ -2702,7 +2703,7 @@ def bell_polynomial(n, k): for p in Partitions(n, length=k): factorial_product = 1 power_factorial_product = 1 - for part, count in p.to_exp_dict().iteritems(): + for part, count in six.iteritems(p.to_exp_dict()): factorial_product *= factorial(count) power_factorial_product *= factorial(part)**count coefficient = factorial(n) // (factorial_product * power_factorial_product) diff --git a/src/sage/combinat/combinatorial_algebra.py b/src/sage/combinat/combinatorial_algebra.py index 003ae8ac6a0..502331bc66e 100644 --- a/src/sage/combinat/combinatorial_algebra.py +++ b/src/sage/combinat/combinatorial_algebra.py @@ -65,6 +65,9 @@ from sage.categories.all import AlgebrasWithBasis from sage.structure.element import Element +import six + + # TODO: migrate this completely to the combinatorial free module + categories framework # for backward compatibility @@ -299,8 +302,8 @@ def product(self, left, right): #Do the case where the user specifies how to multiply basis elements if hasattr(self, '_multiply_basis'): - for (left_m, left_c) in left._monomial_coefficients.iteritems(): - for (right_m, right_c) in right._monomial_coefficients.iteritems(): + for (left_m, left_c) in six.iteritems(left._monomial_coefficients): + for (right_m, right_c) in six.iteritems(right._monomial_coefficients): res = self._multiply_basis(left_m, right_m) coeffprod = left_c * right_c #Handle the case where the user returns a dictionary @@ -313,7 +316,7 @@ def product(self, left, right): else: z_elt[res] = z_elt.get(res, ABRzero) + coeffprod continue - for m, c in res.iteritems(): + for m, c in six.iteritems(res): z_elt[m] = z_elt.get(m, ABRzero) + coeffprod * c #We assume that the user handles the multiplication correctly on @@ -332,7 +335,7 @@ def product(self, left, right): BR = self.base_ring() zero = BR(0) del_list = [] - for m, c in z_elt.iteritems(): + for m, c in six.iteritems(z_elt): if c == zero: del_list.append(m) for m in del_list: diff --git a/src/sage/combinat/crystals/monomial_crystals.py b/src/sage/combinat/crystals/monomial_crystals.py index d569bf296d3..5889a681b2f 100644 --- a/src/sage/combinat/crystals/monomial_crystals.py +++ b/src/sage/combinat/crystals/monomial_crystals.py @@ -112,6 +112,9 @@ from sage.matrix.matrix import is_Matrix from sage.matrix.matrix_space import MatrixSpace +import six + + class NakajimaMonomial(Element): r""" An element of the monomial crystal. @@ -187,7 +190,7 @@ def _repr_Y(self): if not self._Y: return "1" - L = sorted(self._Y.iteritems(), key=lambda x: (x[0][0], x[0][1])) + L = sorted(six.iteritems(self._Y), key=lambda x: (x[0][0], x[0][1])) exp = lambda e: "^{}".format(e) if e != 1 else "" return ' '.join("Y({},{})".format(mon[0][0], mon[0][1]) + exp(mon[1]) for mon in L) @@ -211,7 +214,7 @@ def _repr_A(self): if not Y and not self._A: return "1" - L = sorted(Y.iteritems(), key=lambda x: (x[0][0], x[0][1])) + L = sorted(six.iteritems(Y), key=lambda x: (x[0][0], x[0][1])) exp = lambda e: "^{}".format(e) if e != 1 else "" ret = ' '.join("Y({},{})".format(mon[0][0], mon[0][1]) + exp(mon[1]) for mon in L) @@ -219,7 +222,7 @@ def _repr_A(self): return ret if Y: ret += ' ' - L = sorted(self._A.iteritems(), key=lambda x: (x[0][0], x[0][1])) + L = sorted(six.iteritems(self._A), key=lambda x: (x[0][0], x[0][1])) return ret + ' '.join("A({},{})".format(mon[0][0], mon[0][1]) + exp(mon[1]) for mon in L) @@ -233,7 +236,7 @@ def __hash__(self): 4715601665014767730 # 64-bit -512614286 # 32-bit """ - return hash(frozenset(tuple(self._Y.iteritems()))) + return hash(frozenset(tuple(six.iteritems(self._Y)))) def __eq__(self, other): r""" @@ -310,7 +313,7 @@ def _latex_Y(self): if not self._Y: return "\\boldsymbol{1}" - L = sorted(self._Y.iteritems(), key=lambda x:(x[0][0],x[0][1])) + L = sorted(six.iteritems(self._Y), key=lambda x:(x[0][0],x[0][1])) return_str = '' for x in L: if x[1] != 1: @@ -338,14 +341,14 @@ def _latex_A(self): if not Y and not self._A: return "\\boldsymbol{1}" - L = sorted(Y.iteritems(), key=lambda x:(x[0][0],x[0][1])) + L = sorted(six.iteritems(Y), key=lambda x:(x[0][0],x[0][1])) return_str = '' for x in L: if x[1] != 1: return_str += "Y_{%s,%s}"%(x[0][0],x[0][1]) + "^{%s} "%x[1] else: return_str += "Y_{%s,%s} "%(x[0][0],x[0][1]) - L = sorted(self._A.iteritems(), key=lambda x:(x[0][0],x[0][1])) + L = sorted(six.iteritems(self._A), key=lambda x:(x[0][0],x[0][1])) for x in L: if x[1] != 1: return_str += "A_{%s,%s}"%(x[0][0],x[0][1]) + "^{%s} "%x[1] @@ -372,7 +375,7 @@ def _classical_weight(self): """ P = self.parent().weight_lattice_realization() La = P.fundamental_weights() - return P(sum(v*La[k[0]] for k,v in self._Y.iteritems())) + return P(sum(v*La[k[0]] for k,v in six.iteritems(self._Y))) def weight_in_root_lattice(self): r""" @@ -398,7 +401,7 @@ def weight_in_root_lattice(self): """ Q = RootSystem(self.parent().cartan_type()).root_lattice() al = Q.simple_roots() - return Q.sum(e*al[k[0]] for k,e in self._A.iteritems()) + return Q.sum(e*al[k[0]] for k,e in six.iteritems(self._A)) def weight(self): r""" @@ -476,7 +479,7 @@ def phi(self, i): continue else: d[(i,a)] = 0 - S = sorted((x for x in d.iteritems() if x[0][0] == i), key=lambda x: x[0][1]) + S = sorted((x for x in six.iteritems(d) 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): @@ -508,7 +511,7 @@ def _ke(self, i): d[(i,a)] = 0 total = ZZ.zero() L = [] - S = sorted((x for x in d.iteritems() if x[0][0] == i), key=lambda x: x[0][1]) + S = sorted((x for x in six.iteritems(d) if x[0][0] == i), key=lambda x: x[0][1]) for var,exp in S: total += exp if total == phi: @@ -541,7 +544,7 @@ def _kf(self, i): continue else: d[(i,a)] = 0 - S = sorted((x for x in d.iteritems() if x[0][0] == i), key=lambda x: x[0][1]) + S = sorted((x for x in six.iteritems(d) if x[0][0] == i), key=lambda x: x[0][1]) sum = 0 phi = self.phi(i) for var,exp in S: @@ -611,7 +614,7 @@ def e(self, i): if cm[j_index,i-shift] != 0: Aik[(j, ke+c)] = cm[j_index,i-shift] # Multiply by Aik - for key,value in Aik.iteritems(): + for key,value in six.iteritems(Aik): if key in newdict: if newdict[key] == -value: # The result would be a 0 exponent del newdict[key] @@ -660,7 +663,7 @@ def f(self, i): if cm[j_index,i-shift] != 0: Aik[(j, kf+c)] = -cm[j_index,i-shift] # Multiply by Aik - for key,value in Aik.iteritems(): + for key,value in six.iteritems(Aik): if key in newdict: if newdict[key] == -value: # The result would be a 0 exponent del newdict[key] @@ -921,7 +924,7 @@ def _element_constructor_(self, Y=None, A=None): if ct.is_finite(): shift = 1 Y = {} - for k,v in A.iteritems(): + for k,v in six.iteritems(A): Y[k] = Y.get(k, 0) + v Y[(k[0],k[1]+1)] = Y.get((k[0],k[1]+1), 0) + v for j_index,j in enumerate(I): diff --git a/src/sage/combinat/designs/block_design.py b/src/sage/combinat/designs/block_design.py index 70eb78ad53f..cfa672d5757 100644 --- a/src/sage/combinat/designs/block_design.py +++ b/src/sage/combinat/designs/block_design.py @@ -68,6 +68,9 @@ from sage.matrix.matrix_space import MatrixSpace +import six + + BlockDesign = IncidenceStructure ### utility functions ------------------------------------------------------- @@ -273,7 +276,7 @@ def ProjectiveGeometryDesign(n, d, F, algorithm=None, point_coordinates=True, ch blocks.append(b) B = BlockDesign(len(points), blocks, name="ProjectiveGeometryDesign", check=check) if point_coordinates: - B.relabel({i:p[0] for p,i in points.iteritems()}) + B.relabel({i:p[0] for p,i in six.iteritems(points)}) elif algorithm == "gap": # Requires GAP's Design from sage.interfaces.gap import gap @@ -870,7 +873,7 @@ def AffineGeometryDesign(n, d, F, point_coordinates=True, check=True): B = BlockDesign(len(points), blocks, name="AffineGeometryDesign", check=check) if point_coordinates: - rd = {i:p[0][1:] for p,i in points.iteritems()} + rd = {i:p[0][1:] for p,i in six.iteritems(points)} for v in rd.values(): v.set_immutable() B.relabel(rd) diff --git a/src/sage/combinat/designs/database.py b/src/sage/combinat/designs/database.py index 4b2128911f8..93e83448adc 100644 --- a/src/sage/combinat/designs/database.py +++ b/src/sage/combinat/designs/database.py @@ -47,6 +47,7 @@ --------- """ from __future__ import print_function, absolute_import +import six from six.moves import range from sage.combinat.designs.orthogonal_arrays import (OA_from_quasi_difference_matrix, @@ -1684,7 +1685,7 @@ def OA_10_469(): blocks[len(B)].append(B) # Product of each symmetric design with the OA - for b_size,symmetric_design in blocks.iteritems(): + for b_size,symmetric_design in six.iteritems(blocks): matrix = _reorder_matrix(symmetric_design) OA.extend([[B[xx] for xx in R] for R in incomplete_orthogonal_array(9,b_size,[1]*b_size) @@ -2694,7 +2695,7 @@ def QDM_57_9_1_1_8(): (12,413) : ((0,1,436,546,977,467,242,3695,682,483,3026,461,1334), _ref_Abel_v_12_t), } # Translate all V(m,t) into (mt+1,m+2;1,0;t)-QDM constructors -for (m,t),(vec,source) in Vmt_vectors.iteritems(): +for (m,t),(vec,source) in six.iteritems(Vmt_vectors): n,k,lmbda,mu,u = (m*t+1,m+2,1,0,t) if not (n+u,lmbda) in QDM: QDM[n+u,lmbda] = {} diff --git a/src/sage/combinat/designs/difference_family.py b/src/sage/combinat/designs/difference_family.py index b76df57621c..b8881e3e369 100644 --- a/src/sage/combinat/designs/difference_family.py +++ b/src/sage/combinat/designs/difference_family.py @@ -51,6 +51,7 @@ from __future__ import division, print_function, absolute_import from builtins import zip +import six from six import itervalues from six.moves import range @@ -1537,7 +1538,7 @@ def difference_family(v, k, l=1, existence=False, explain_construction=False, ch elif explain_construction: return "The database contains a ({},{},{})-difference family".format(v,k,l) - vv, blocks = next(DF[v,k,l].iteritems()) + vv, blocks = next(six.iteritems(DF[v,k,l])) # Build the group from sage.rings.finite_rings.integer_mod_ring import Zmod diff --git a/src/sage/combinat/designs/ext_rep.py b/src/sage/combinat/designs/ext_rep.py index 3c187efece0..17930329a8e 100644 --- a/src/sage/combinat/designs/ext_rep.py +++ b/src/sage/combinat/designs/ext_rep.py @@ -43,6 +43,7 @@ import sys # import compatible with py2 and py3 +import six from six.moves.urllib.request import urlopen from six import string_types @@ -871,7 +872,7 @@ def _start_element(self, name, attrs): elif name == 'designs': pass # self.outf.write(' <%s>\n' % name) if self.in_item: - for k, v in attrs.iteritems(): + for k, v in six.iteritems(attrs): attrs[k] = _encode_attribute(v) new_node = (name, attrs, []) self.node_stack.append(new_node) diff --git a/src/sage/combinat/designs/incidence_structures.py b/src/sage/combinat/designs/incidence_structures.py index 6ecb026d15a..001d2181017 100644 --- a/src/sage/combinat/designs/incidence_structures.py +++ b/src/sage/combinat/designs/incidence_structures.py @@ -40,6 +40,7 @@ #*************************************************************************** from __future__ import print_function +import six from six import itervalues from six.moves import range @@ -483,8 +484,8 @@ def is_isomorphic(self, other, certificate=False): if A == B: if certificate: - B_canon_rev = {y:x for x,y in B_canon.iteritems()} - return {x:B_canon_rev[xint] for x,xint in A_canon.iteritems()} + B_canon_rev = {y:x for x,y in six.iteritems(B_canon)} + return {x:B_canon_rev[xint] for x,xint in six.iteritems(A_canon)} else: return True else: @@ -898,7 +899,7 @@ def degrees(self, size=None): for s in combinations(b,size): d[s]+=1 if self._point_to_index: - return {tuple([self._points[x] for x in s]):v for s,v in d.iteritems()} + return {tuple([self._points[x] for x in s]):v for s,v in six.iteritems(d)} else: return d @@ -1426,7 +1427,7 @@ def packing(self, solver=None, verbose=0): p.solve(log=verbose) return [[self._points[x] for x in self._blocks[i]] - for i,v in p.get_values(b).iteritems() if v] + for i,v in six.iteritems(p.get_values(b)) if v] def is_t_design(self, t=None, v=None, k=None, l=None, return_parameters=False): r""" @@ -1948,7 +1949,7 @@ def is_resolvable(self, certificate=False, solver=None, verbose=0, check=True): else: # each class is stored as the list of indices of its blocks self._classes = [[] for _ in range(n_classes)] - for (t,i),v in p.get_values(b).iteritems(): + for (t,i),v in six.iteritems(p.get_values(b)): if v: self._classes[t].append(self._blocks[i]) @@ -2060,7 +2061,7 @@ def coloring(self, k=None, solver=None, verbose=0): col = [[] for i in range(k)] - for (x,i),v in p.get_values(b).iteritems(): + for (x,i),v in six.iteritems(p.get_values(b)): if v: col[i].append(self._points[x]) diff --git a/src/sage/combinat/designs/latin_squares.py b/src/sage/combinat/designs/latin_squares.py index 6dcadb67d3a..f9a14402558 100644 --- a/src/sage/combinat/designs/latin_squares.py +++ b/src/sage/combinat/designs/latin_squares.py @@ -128,6 +128,9 @@ from sage.categories.sets_cat import EmptySetError from sage.misc.unknown import Unknown +import six + + def are_mutually_orthogonal_latin_squares(l, verbose=False): r""" Check wether the list of matrices in ``l`` form mutually orthogonal latin @@ -470,7 +473,7 @@ def latin_square_product(M,N,*others): for jj in range(n)} L = lambda i_j: i_j[0] * n + i_j[1] - D = {(L(c[0]),L(c[1])): L(v) for c,v in D.iteritems()} + D = {(L(c[0]),L(c[1])): L(v) for c,v in six.iteritems(D)} P = Matrix(D) if others: diff --git a/src/sage/combinat/designs/orthogonal_arrays.py b/src/sage/combinat/designs/orthogonal_arrays.py index 887f866cd98..d149722e4d1 100644 --- a/src/sage/combinat/designs/orthogonal_arrays.py +++ b/src/sage/combinat/designs/orthogonal_arrays.py @@ -58,6 +58,7 @@ from __future__ import print_function, absolute_import from builtins import zip +import six from six import itervalues from six.moves import range @@ -1375,7 +1376,7 @@ def incomplete_orthogonal_array(k,n,holes,resolvable=False, existence=False): # From a quasi-difference matrix elif number_of_holes==1 and any(uu==sum_of_holes and mu<=1 and lmbda==1 and k<=kk+1 for (nn,lmbda,mu,uu),(kk,_) in QDM.get((n,1),{}).iteritems()): - for (nn,lmbda,mu,uu),(kk,f) in QDM[n,1].iteritems(): + for (nn,lmbda,mu,uu),(kk,f) in six.iteritems(QDM[n,1]): if uu==sum_of_holes and mu<=1 and lmbda==1 and k<=kk+1: break G,M = f() @@ -1806,8 +1807,8 @@ def OA_from_quasi_difference_matrix(M,G,add_col=True,fill_hole=True): # A cache for addition in G G_sum = [[0]*Gn for _ in range(Gn)] - for x,i in G_to_int.iteritems(): - for xx,ii in G_to_int.iteritems(): + for x,i in six.iteritems(G_to_int): + for xx,ii in six.iteritems(G_to_int): G_sum[i][ii] = G_to_int[x+xx] # Convert M to integers diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index f366bce30ac..fa668d81c4b 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -931,6 +931,7 @@ from __future__ import print_function from builtins import zip +import six from six.moves import range from six import itervalues @@ -2062,7 +2063,7 @@ def _epsilon_successors_(self, fsm=None): _epsilon_successors_dict_[self].remove([]) # delete starting state if not _epsilon_successors_dict_[self]: del _epsilon_successors_dict_[self] - for s, outputs in _epsilon_successors_dict_.iteritems(): + for s, outputs in six.iteritems(_epsilon_successors_dict_): _epsilon_successors_dict_[s] = [t for t, _ in itertools.groupby(sorted(outputs))] return _epsilon_successors_dict_ @@ -3202,10 +3203,10 @@ def __init__(self, elif hasattr(data, 'iteritems'): # data is a dict (or something similar), # format: key = from_state, value = iterator of transitions - for (sf, iter_transitions) in data.iteritems(): + for (sf, iter_transitions) in six.iteritems(data): self.add_state(sf) if hasattr(iter_transitions, 'iteritems'): - for (st, transition) in iter_transitions.iteritems(): + for (st, transition) in six.iteritems(iter_transitions): self.add_state(st) if is_FSMTransition(transition): self.add_transition(transition) @@ -4955,7 +4956,7 @@ def key_function(s): key=key_function )) - for ((source, target), transitions) in adjacent.iteritems(): + for ((source, target), transitions) in six.iteritems(adjacent): if len(transitions) > 0: labels = [] for transition in transitions: @@ -6582,14 +6583,14 @@ def _iter_process_simple_(self, iterator): "'simple' iterator cannot be used " "here." % (len(current),)) - pos, states = next(current.iteritems()) + pos, states = next(six.iteritems(current)) if len(states) > 1: raise RuntimeError("Process has branched " "(visiting %s states in branch). The " "'simple' iterator cannot be used " "here." % (len(states),)) - state, branch = next(states.iteritems()) + state, branch = next(six.iteritems(states)) if len(branch.outputs) > 1: raise RuntimeError("Process has branched. " "(%s different outputs in branch). The " @@ -9839,7 +9840,7 @@ def find_final_word_out(state): # have been computed as it may not be permissible to stop at a # formerly non-final state unless a cycle has been completed. - for (state, position), final_word_out in cache.iteritems(): + for (state, position), final_word_out in six.iteritems(cache): if position == 0 and final_word_out is not None: state.is_final = True state.final_word_out = final_word_out @@ -11764,7 +11765,7 @@ def is_equivalent(self, other): B = other.minimization().relabeled() labels = {B.process(path)[1].label(): state.label() - for (state, path) in address.iteritems()} + for (state, path) in six.iteritems(address)} try: return A == B.relabeled(labels=labels) except KeyError: @@ -14423,8 +14424,8 @@ def __repr__(self): """ data = sorted( (state, pos, tape_cache, outputs) - for pos, states in self.iteritems() - for state, (tape_cache, outputs) in states.iteritems()) + for pos, states in six.iteritems(self) + for state, (tape_cache, outputs) in six.iteritems(states)) branch = "branch" if len(data) == 1 else "branches" result = "process (%s %s)" % (len(data), branch) for s, sdata in itertools.groupby(data, lambda x: x[0]): @@ -14702,7 +14703,7 @@ def _push_branches_(self, state, tape_cache, outputs): 'but output is written.' % (state,)) for eps_state, eps_outputs in \ - state._epsilon_successors_(self.fsm).iteritems(): + six.iteritems(state._epsilon_successors_(self.fsm)): if eps_state == state: continue # "eps_state == state" means epsilon cycle @@ -14903,7 +14904,7 @@ def step(current_state, input_tape, outputs): return states_dict = self._current_.pop(heapq.heappop(self._current_positions_)) - for state, branch in states_dict.iteritems(): + for state, branch in six.iteritems(states_dict): step(state, branch.tape_cache, branch.outputs) return self._current_ diff --git a/src/sage/combinat/free_module.py b/src/sage/combinat/free_module.py index a83b0d57e84..83e0863b3bc 100644 --- a/src/sage/combinat/free_module.py +++ b/src/sage/combinat/free_module.py @@ -30,6 +30,9 @@ from sage.typeset.ascii_art import AsciiArt, empty_ascii_art from sage.typeset.unicode_art import UnicodeArt, empty_unicode_art +import six + + # TODO: move the content of this class to CombinatorialFreeModule.Element and ModulesWithBasis.Element class CombinatorialFreeModuleElement(Element): def __init__(self, M, x): @@ -67,7 +70,7 @@ def __iter__(self): sage: [i for i in sorted(a)] [([2, 1], 1), ([3], 1)] """ - return self._monomial_coefficients.iteritems() + return six.iteritems(self._monomial_coefficients) def __contains__(self, x): """ @@ -1650,7 +1653,7 @@ def from_vector(self, vector): True """ cc = self.get_order() - return self._from_dict(dict( (cc[index], coeff) for (index,coeff) in vector.iteritems())) + return self._from_dict(dict( (cc[index], coeff) for (index,coeff) in six.iteritems(vector))) def __cmp__(self, other): """ @@ -1880,9 +1883,9 @@ def _from_dict(self, d, coerce=False, remove_zeros=True): assert isinstance(d, dict) if coerce: R = self.base_ring() - d = {key: R(coeff) for key,coeff in d.iteritems()} + d = {key: R(coeff) for key,coeff in six.iteritems(d)} if remove_zeros: - d = {key: coeff for key, coeff in d.iteritems() if coeff} + d = {key: coeff for key, coeff in six.iteritems(d) if coeff} return self.element_class( self, d ) class CombinatorialFreeModule_Tensor(CombinatorialFreeModule): diff --git a/src/sage/combinat/fully_packed_loop.py b/src/sage/combinat/fully_packed_loop.py index 9d55f7b8d4f..7aa8fec36ff 100644 --- a/src/sage/combinat/fully_packed_loop.py +++ b/src/sage/combinat/fully_packed_loop.py @@ -22,6 +22,9 @@ from sage.misc.lazy_attribute import lazy_attribute +import six + + class FullyPackedLoop(Element): r""" A class for fully packed loops. @@ -1112,7 +1115,7 @@ def _vertex_dictionary(self): for j in range(n): vertices[(i, j)] = 0 - for end, vertex in self._end_point_dictionary.iteritems(): + for end, vertex in six.iteritems(self._end_point_dictionary): vertices[vertex] = end return vertices diff --git a/src/sage/combinat/k_tableau.py b/src/sage/combinat/k_tableau.py index 7b1449fc3d1..9cf77ae7569 100644 --- a/src/sage/combinat/k_tableau.py +++ b/src/sage/combinat/k_tableau.py @@ -1027,7 +1027,7 @@ def list_of_standard_cells(self): r = self[0].count(1) - i - 1 for v in range(1,mu[i]): D = self.dictionary_of_coordinates_at_residues(v+1) - new_D = {a:b for (a,b) in D.iteritems() if all(x not in already_used for x in b)} + new_D = {a:b for (a,b) in six.iteritems(D) if all(x not in already_used for x in b)} r = (r - min([self.k+1 - (x-r)%(self.k+1) for x in new_D]))%(self.k+1) standard_cells.append(new_D[r][-1]) already_used += new_D[r] @@ -4649,4 +4649,8 @@ def intermediate_shapes(t): # Deprecations from trac:18555. July 2016 from sage.misc.superseded import deprecated_function_alias + +import six + + StrongTableaux.global_options = deprecated_function_alias(18555, StrongTableaux.options) diff --git a/src/sage/combinat/ncsf_qsym/qsym.py b/src/sage/combinat/ncsf_qsym/qsym.py index 9e7ddce77e1..b40615f3c7b 100644 --- a/src/sage/combinat/ncsf_qsym/qsym.py +++ b/src/sage/combinat/ncsf_qsym/qsym.py @@ -86,6 +86,9 @@ from sage.categories.morphism import SetMorphism from sage.categories.homset import Hom +import six + + class QuasiSymmetricFunctions(UniqueRepresentation, Parent): r""" .. rubric:: The Hopf algebra of quasisymmetric functions. @@ -674,7 +677,7 @@ def from_polynomial(self, f, check=True): assert self.base_ring() == f.base_ring() exponent_coefficient = f.dict() z = {} - for (e, c) in exponent_coefficient.iteritems(): + for (e, c) in six.iteritems(exponent_coefficient): I = Compositions()([ei for ei in e if ei > 0]) if I not in z: z[I] = c diff --git a/src/sage/combinat/partition.py b/src/sage/combinat/partition.py index c36f656b9fa..98d82745b47 100644 --- a/src/sage/combinat/partition.py +++ b/src/sage/combinat/partition.py @@ -280,6 +280,7 @@ #***************************************************************************** from __future__ import print_function, absolute_import +import six from six.moves import range from sage.interfaces.all import gap @@ -3199,7 +3200,7 @@ def centralizer_size(self, t=0, q=0): 1 """ size = prod(i ** mi * factorial(mi) - for i, mi in self.to_exp_dict().iteritems()) + for i, mi in six.iteritems(self.to_exp_dict())) if t or q: size *= prod((ZZ.one() - q ** j) / (ZZ.one() - t ** j) for j in self) diff --git a/src/sage/combinat/posets/lattices.py b/src/sage/combinat/posets/lattices.py index cc23b405680..371fda91bc1 100644 --- a/src/sage/combinat/posets/lattices.py +++ b/src/sage/combinat/posets/lattices.py @@ -134,6 +134,9 @@ JoinSemilatticeElement) from sage.combinat.posets.hasse_diagram import LatticeError +import six + + #################################################################################### def MeetSemilattice(data=None, *args, **options): @@ -1383,7 +1386,7 @@ def is_relatively_complemented(self, certificate=False): for e1 in range(n-1): C = Counter(flatten([H.neighbors_out(e2) for e2 in H.neighbors_out(e1)])) - for e3, c in C.iteritems(): + for e3, c in six.iteritems(C): if c == 1 and len(H.closed_interval(e1, e3)) == 3: if not certificate: return False diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 31bf5c1a10a..9ee9d6291e5 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -254,6 +254,7 @@ # python3 from __future__ import division, print_function, absolute_import +import six from six.moves import range from six import itervalues @@ -3010,7 +3011,7 @@ def init_LP(k,cycles,inc_P): # We create the digraphs of all color classes linear_extensions = [hasse_diagram.copy() for i in range(k)] - for ((u,v),i),x in p.get_values(b).iteritems(): + for ((u,v),i),x in six.iteritems(p.get_values(b)): if x == 1: linear_extensions[i].add_edge(u,v) @@ -4932,7 +4933,7 @@ def canonical_label(self, algorithm=None): """ canonical_label = self._hasse_diagram.canonical_label(certificate=True, algorithm=algorithm)[1] - canonical_label = {self._elements[v]:i for v,i in canonical_label.iteritems()} + canonical_label = {self._elements[v]:i for v,i in six.iteritems(canonical_label)} return self.relabel(canonical_label) def with_linear_extension(self, linear_extension): diff --git a/src/sage/combinat/root_system/ambient_space.py b/src/sage/combinat/root_system/ambient_space.py index f90f1139daf..9cc64aa8c28 100644 --- a/src/sage/combinat/root_system/ambient_space.py +++ b/src/sage/combinat/root_system/ambient_space.py @@ -15,6 +15,9 @@ from sage.rings.all import ZZ, QQ from sage.categories.homset import End +import six + + class AmbientSpace(CombinatorialFreeModule): r""" Abstract class for ambient spaces @@ -386,7 +389,7 @@ def inner_product(self, lambdacheck): lambdacheck_mc = lambdacheck._monomial_coefficients result = self.parent().base_ring().zero() - for t,c in lambdacheck_mc.iteritems(): + for t,c in six.iteritems(lambdacheck_mc): if t not in self_mc: continue result += c*self_mc[t] diff --git a/src/sage/combinat/root_system/root_lattice_realization_algebras.py b/src/sage/combinat/root_system/root_lattice_realization_algebras.py index 3f11d5f9627..7942b6de883 100644 --- a/src/sage/combinat/root_system/root_lattice_realization_algebras.py +++ b/src/sage/combinat/root_system/root_lattice_realization_algebras.py @@ -21,6 +21,9 @@ from sage.modules.free_module_element import vector from sage.combinat.root_system.hecke_algebra_representation import HeckeAlgebraRepresentation +import six + + class Algebras(AlgebrasCategory): """ The category of group algebras of root lattice realizations. @@ -116,7 +119,7 @@ def from_polynomial(self, p): .. TODO:: make this work for Laurent polynomials too """ L = self.basis().keys() - return self.sum_of_terms((L.from_vector(vector(t)), c) for (t,c) in p.dict().iteritems()) + return self.sum_of_terms((L.from_vector(vector(t)), c) for (t,c) in six.iteritems(p.dict())) @cached_method def divided_difference_on_basis(self, weight, i): diff --git a/src/sage/combinat/root_system/type_folded.py b/src/sage/combinat/root_system/type_folded.py index 3b758c06b5b..9da9a4a796f 100644 --- a/src/sage/combinat/root_system/type_folded.py +++ b/src/sage/combinat/root_system/type_folded.py @@ -19,6 +19,9 @@ from sage.sets.family import Family from sage.combinat.root_system.cartan_type import CartanType +import six + + class CartanTypeFolded(UniqueRepresentation, SageObject): r""" A Cartan type realized from a (Dynkin) diagram folding. @@ -178,7 +181,7 @@ def __classcall_private__(cls, cartan_type, virtual, orbit): if isinstance(orbit, dict): i_set = cartan_type.index_set() orb = [None]*len(i_set) - for k,v in orbit.iteritems(): + for k,v in six.iteritems(orbit): orb[i_set.index(k)] = tuple(v) orbit = tuple(orb) else: diff --git a/src/sage/combinat/root_system/type_reducible.py b/src/sage/combinat/root_system/type_reducible.py index 8b19ead34ba..eb919335e74 100644 --- a/src/sage/combinat/root_system/type_reducible.py +++ b/src/sage/combinat/root_system/type_reducible.py @@ -20,6 +20,9 @@ import sage.combinat.root_system as root_system from sage.structure.sage_object import SageObject +import six + + class CartanType(SageObject, CartanType_abstract): r""" A class for reducible Cartan types. @@ -83,7 +86,7 @@ def __init__(self, types): Internally, this relabelling is stored as a dictionary:: sage: t = CartanType(["A",4], ["BC",5,2], ["C",3]) - sage: sorted(t._index_relabelling.iteritems()) + sage: sorted(six.iteritems(t._index_relabelling)) [((0, 1), 1), ((0, 2), 2), ((0, 3), 3), ((0, 4), 4), ((1, 0), 5), ((1, 1), 6), ((1, 2), 7), ((1, 3), 8), ((1, 4), 9), ((1, 5), 10), ((2, 1), 11), ((2, 2), 12), ((2, 3), 13)] diff --git a/src/sage/combinat/sf/character.py b/src/sage/combinat/sf/character.py index 0f3cb7f57e8..75f19fc7b58 100644 --- a/src/sage/combinat/sf/character.py +++ b/src/sage/combinat/sf/character.py @@ -36,6 +36,9 @@ from sage.functions.other import binomial from sage.rings.integer import Integer +import six + + class generic_character(SFA_generic): def _my_key(self, la): r""" @@ -428,7 +431,7 @@ def _b_power_gamma(self, gamma): """ return self._p.prod( self._b_power_k_r(Integer(k),Integer(r)) - for (k,r) in gamma.to_exp_dict().iteritems() ) + for (k,r) in six.iteritems(gamma.to_exp_dict()) ) def _self_to_power_on_basis(self, lam): r""" diff --git a/src/sage/combinat/sf/classical.py b/src/sage/combinat/sf/classical.py index 755cae8d72e..c0af8d5b6b1 100644 --- a/src/sage/combinat/sf/classical.py +++ b/src/sage/combinat/sf/classical.py @@ -34,6 +34,9 @@ from . import jack from . import orthotriang +import six + + ZZ = IntegerRing() QQ = RationalField() @@ -234,7 +237,7 @@ def _element_constructor_(self, x): raise TypeError("no coerce map from x's parent's base ring (= %s) to self's base ring (= %s)"%(PBR, self.base_ring())) z_elt = {} - for m, c in x._monomial_coefficients.iteritems(): + for m, c in six.iteritems(x._monomial_coefficients): n = sum(m) P._m_cache(n) for part in P._self_to_m_cache[n][m]: diff --git a/src/sage/combinat/sf/kfpoly.py b/src/sage/combinat/sf/kfpoly.py index ecf5072c3c8..6763e56a371 100644 --- a/src/sage/combinat/sf/kfpoly.py +++ b/src/sage/combinat/sf/kfpoly.py @@ -27,6 +27,9 @@ from sage.rings.integer_ring import ZZ +import six + + def KostkaFoulkesPolynomial(mu, nu, t=None): r""" Returns the Kostka-Foulkes polynomial `K_{\mu, \nu}(t)`. @@ -130,41 +133,41 @@ def schur_to_hl(mu, t=None): sage: schur_to_hl([1,1,1]) {[1, 1, 1]: 1} sage: a = schur_to_hl([2,1]) - sage: for mc in sorted(a.iteritems()): print(mc) + sage: for mc in sorted(six.iteritems(a)): print(mc) ([1, 1, 1], t^2 + t) ([2, 1], 1) sage: a = schur_to_hl([3]) - sage: for mc in sorted(a.iteritems()): print(mc) + sage: for mc in sorted(six.iteritems(a)): print(mc) ([1, 1, 1], t^3) ([2, 1], t) ([3], 1) sage: a = schur_to_hl([4]) - sage: for mc in sorted(a.iteritems()): print(mc) + sage: for mc in sorted(six.iteritems(a)): print(mc) ([1, 1, 1, 1], t^6) ([2, 1, 1], t^3) ([2, 2], t^2) ([3, 1], t) ([4], 1) sage: a = schur_to_hl([3,1]) - sage: for mc in sorted(a.iteritems()): print(mc) + sage: for mc in sorted(six.iteritems(a)): print(mc) ([1, 1, 1, 1], t^5 + t^4 + t^3) ([2, 1, 1], t^2 + t) ([2, 2], t) ([3, 1], 1) sage: a = schur_to_hl([2,2]) - sage: for mc in sorted(a.iteritems()): print(mc) + sage: for mc in sorted(six.iteritems(a)): print(mc) ([1, 1, 1, 1], t^4 + t^2) ([2, 1, 1], t) ([2, 2], 1) sage: a = schur_to_hl([2,1,1]) - sage: for mc in sorted(a.iteritems()): print(mc) + sage: for mc in sorted(six.iteritems(a)): print(mc) ([1, 1, 1, 1], t^3 + t^2 + t) ([2, 1, 1], 1) sage: a = schur_to_hl([1,1,1,1]) - sage: for mc in sorted(a.iteritems()): print(mc) + sage: for mc in sorted(six.iteritems(a)): print(mc) ([1, 1, 1, 1], 1) sage: a = schur_to_hl([2,2,2]) - sage: for mc in sorted(a.iteritems()): print(mc) + sage: for mc in sorted(six.iteritems(a)): print(mc) ([1, 1, 1, 1, 1, 1], t^9 + t^7 + t^6 + t^5 + t^3) ([2, 1, 1, 1, 1], t^4 + t^2) ([2, 2, 1, 1], t) diff --git a/src/sage/combinat/sf/monomial.py b/src/sage/combinat/sf/monomial.py index fbc4c1386c6..02c6f39e462 100644 --- a/src/sage/combinat/sf/monomial.py +++ b/src/sage/combinat/sf/monomial.py @@ -113,8 +113,8 @@ def _multiply(self, left, right): # return symmetrica.mult_monomial_monomial(left, right) z_elt = {} - for (left_m, left_c) in left._monomial_coefficients.iteritems(): - for (right_m, right_c) in right._monomial_coefficients.iteritems(): + for (left_m, left_c) in six.iteritems(left._monomial_coefficients): + for (right_m, right_c) in six.iteritems(right._monomial_coefficients): #Hack due to symmetrica crashing when both of the #partitions are the empty partition @@ -172,7 +172,7 @@ def from_polynomial(self, f, check=True): """ assert self.base_ring() == f.base_ring() out = self.sum_of_terms((Partition(e), c) - for (e,c) in f.dict().iteritems() + for (e,c) in six.iteritems(f.dict()) if tuple(sorted(e)) == tuple(reversed(e))) if check and out.expand(f.parent().ngens(),f.parent().gens()) != f: raise ValueError("%s is not a symmetric polynomial"%f) @@ -223,7 +223,7 @@ def from_polynomial_exp(self, p): """ assert self.base_ring() == p.parent().base_ring() return self.sum_of_terms((Partition(exp=monomial), coeff) - for (monomial, coeff) in p.dict().iteritems()) + for (monomial, coeff) in six.iteritems(p.dict())) def antipode_by_coercion(self, element): r""" @@ -302,4 +302,8 @@ def expand(self, n, alphabet='x'): # Backward compatibility for unpickling from sage.structure.sage_object import register_unpickle_override + +import six + + register_unpickle_override('sage.combinat.sf.monomial', 'SymmetricFunctionAlgebraElement_monomial', SymmetricFunctionAlgebra_monomial.Element) diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py index 43c6d810ef4..c62e860ea15 100644 --- a/src/sage/combinat/sf/sfa.py +++ b/src/sage/combinat/sf/sfa.py @@ -299,6 +299,10 @@ def is_SymmetricFunction(x): ## Bases categories from sage.categories.realizations import Category_realization_of_parent + +import six + + class SymmetricFunctionsBases(Category_realization_of_parent): r""" The category of bases of the ring of symmetric functions. @@ -1624,7 +1628,7 @@ def _change_by_proportionality(self, x, function): """ BR = self.base_ring() z_elt = {} - for m, c in x._monomial_coefficients.iteritems(): + for m, c in six.iteritems(x._monomial_coefficients): coeff = function(m) z_elt[m] = BR( c*coeff ) return self._from_dict(z_elt) @@ -1709,7 +1713,7 @@ def _apply_multi_module_morphism(self, x, y, f, orthogonal=False): if orthogonal: # could check which of x and y has less terms # for mx, cx in x: - for mx, cx in x._monomial_coefficients.iteritems(): + for mx, cx in six.iteritems(x._monomial_coefficients): if mx not in y._monomial_coefficients: continue else: @@ -1719,8 +1723,8 @@ def _apply_multi_module_morphism(self, x, y, f, orthogonal=False): res += cx*cy*f(mx, mx) return res else: - for mx, cx in x._monomial_coefficients.iteritems(): - for my, cy in y._monomial_coefficients.iteritems(): + for mx, cx in six.iteritems(x._monomial_coefficients): + for my, cy in six.iteritems(y._monomial_coefficients): res += cx*cy*f(mx,my) return res @@ -1804,13 +1808,13 @@ def _from_cache(self, element, cache_function, cache_dict, **subs_dict): BR = self.base_ring() zero = BR.zero() z_elt = {} - for part, c in element.monomial_coefficients().iteritems(): + for part, c in six.iteritems(element.monomial_coefficients()): if sum(part) not in cache_dict: cache_function(sum(part)) # Make sure it is a partition (for #13605), this is # needed for the old kschur functions - TCS part = _Partitions(part) - for part2, c2 in cache_dict[sum(part)][part].iteritems(): + for part2, c2 in six.iteritems(cache_dict[sum(part)][part]): if hasattr(c2,'subs'): # c3 may be in the base ring c3 = c*BR(c2.subs(**subs_dict)) else: @@ -3066,7 +3070,7 @@ def inner_plethysm(self, x): cache = {} ip_pnu_g = parent._inner_plethysm_pnu_g return parent.sum( c*ip_pnu_g(p(x), cache, nu) - for (nu, c) in p(self).monomial_coefficients().iteritems() ) + for (nu, c) in six.iteritems(p(self).monomial_coefficients()) ) def omega(self): diff --git a/src/sage/combinat/species/stream.py b/src/sage/combinat/species/stream.py index 0f0414605f4..87df266e7a2 100644 --- a/src/sage/combinat/species/stream.py +++ b/src/sage/combinat/species/stream.py @@ -10,6 +10,9 @@ import types from sage.structure.sage_object import SageObject +import six + + def _integers_from(n): """ Returns a generator for the integers starting at n. @@ -133,7 +136,7 @@ def __init__(self, gen=None, const=None, func=None): :: - sage: list(sorted(s.__dict__.iteritems())) + sage: list(sorted(six.iteritems(s.__dict__))) [('_constant', 4), ('_gen', None), ('_last_index', 0), @@ -143,7 +146,7 @@ def __init__(self, gen=None, const=None, func=None): :: sage: s = Stream(ZZ) - sage: list(sorted(s.__dict__.iteritems())) + sage: list(sorted(six.iteritems(s.__dict__))) [('_constant', None), ('_gen', ), ('_last_index', -1), diff --git a/src/sage/combinat/subset.py b/src/sage/combinat/subset.py index 409701311cc..d00005c7923 100644 --- a/src/sage/combinat/subset.py +++ b/src/sage/combinat/subset.py @@ -28,6 +28,7 @@ #***************************************************************************** from __future__ import print_function, absolute_import +import six from six.moves import range import sage.misc.prandom as rnd import itertools @@ -824,7 +825,7 @@ def dict_to_list(d): ['a', 'b', 'b', 'b'] """ l = [] - for i,j in d.iteritems(): + for i,j in six.iteritems(d): l.extend([i]*j) return l diff --git a/src/sage/combinat/symmetric_group_algebra.py b/src/sage/combinat/symmetric_group_algebra.py index abd78422aee..2affb7a91a0 100644 --- a/src/sage/combinat/symmetric_group_algebra.py +++ b/src/sage/combinat/symmetric_group_algebra.py @@ -25,6 +25,7 @@ from sage.groups.perm_gps.permgroup_element import PermutationGroupElement import itertools from sage.combinat.permutation_cython import (left_action_same_n, right_action_same_n) +import six # TODO: Remove this function and replace it with the class # TODO: Create parents for other bases (such as the seminormal basis) @@ -701,7 +702,7 @@ def retract_plain(self, f, m): I = RSm.group() pairs = [] P = Permutations(self.n) - for (p, coeff) in f.monomial_coefficients().iteritems(): + for (p, coeff) in six.iteritems(f.monomial_coefficients()): p_ret = P(p).retract_plain(m) if p_ret is not None: pairs.append((I(p_ret), coeff)) @@ -767,7 +768,7 @@ def retract_direct_product(self, f, m): I = RSm.group() dct = {} P = Permutations(self.n) - for (p, coeff) in f.monomial_coefficients().iteritems(): + for (p, coeff) in six.iteritems(f.monomial_coefficients()): p_ret = P(p).retract_direct_product(m) if p_ret is not None: p_ret = I(p_ret) @@ -830,7 +831,7 @@ def retract_okounkov_vershik(self, f, m): I = RSm.group() dct = {} P = Permutations(self.n) - for (p, coeff) in f.monomial_coefficients().iteritems(): + for (p, coeff) in six.iteritems(f.monomial_coefficients()): p_ret = I(P(p).retract_okounkov_vershik(m)) if not p_ret in dct: dct[p_ret] = coeff @@ -1679,7 +1680,7 @@ def epsilon_ik(self, itab, ktab, star=0, mult='l2r'): I = self._indices z_elts = {} epik = epsilon_ik(it, kt, star=star) - for m,c in epik._monomial_coefficients.iteritems(): + for m,c in six.iteritems(epik._monomial_coefficients): z_elts[I(m)] = BR(c) z = self._from_dict(z_elts) diff --git a/src/sage/combinat/symmetric_group_representations.py b/src/sage/combinat/symmetric_group_representations.py index 38331b0064c..8b6371da675 100644 --- a/src/sage/combinat/symmetric_group_representations.py +++ b/src/sage/combinat/symmetric_group_representations.py @@ -28,6 +28,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import print_function +import six from six.moves import range from sage.symbolic.ring import SR @@ -569,7 +570,7 @@ def _word_dict(self): (2, 0, 1, -1, 0): (2, 4, 1, 3, 5)} """ word_dict = {} - for (v,t) in self._tableau_dict.iteritems(): + for (v,t) in six.iteritems(self._tableau_dict): word_dict[v] = sum(reversed(t), ()) return word_dict diff --git a/src/sage/combinat/tiling.py b/src/sage/combinat/tiling.py index 165a6e60509..b6fafeb3907 100644 --- a/src/sage/combinat/tiling.py +++ b/src/sage/combinat/tiling.py @@ -222,6 +222,7 @@ from __future__ import division from builtins import zip +import six from six.moves import range import itertools @@ -997,10 +998,10 @@ def boundary(self): vertical[(x+1, y)] -= 1 edges = [] h = 0.5 - for (x, y), coeff in horizontal.iteritems(): + for (x, y), coeff in six.iteritems(horizontal): if coeff != 0: edges.append(((x-h, y-h), (x+h, y-h))) - for (x, y), coeff in vertical.iteritems(): + for (x, y), coeff in six.iteritems(vertical): if coeff != 0: edges.append(((x-h, y-h), (x-h, y+h))) return edges @@ -1277,7 +1278,7 @@ def coord_to_int_dict(self): sage: r = Polyomino([(0,0,0), (0,0,1), (0,0,2)]) sage: T = TilingSolver([p,q,r], box=(1,1,6)) sage: A = T.coord_to_int_dict() - sage: sorted(A.iteritems()) + sage: sorted(six.iteritems(A)) [((0, 0, 0), 3), ((0, 0, 1), 4), ((0, 0, 2), 5), ((0, 0, 3), 6), ((0, 0, 4), 7), ((0, 0, 5), 8)] Reusable pieces:: @@ -1286,7 +1287,7 @@ def coord_to_int_dict(self): sage: q = Polyomino([(0,0), (0,1), (1,0), (1,1)]) sage: T = TilingSolver([p,q], box=[3,2], reusable=True) sage: B = T.coord_to_int_dict() - sage: sorted(B.iteritems()) + sage: sorted(six.iteritems(B)) [((0, 0), 0), ((0, 1), 1), ((1, 0), 2), ((1, 1), 3), ((2, 0), 4), ((2, 1), 5)] """ if self._reusable: @@ -1309,7 +1310,7 @@ def int_to_coord_dict(self): sage: r = Polyomino([(0,0,0), (0,0,1), (0,0,2)]) sage: T = TilingSolver([p,q,r], box=(1,1,6)) sage: B = T.int_to_coord_dict() - sage: sorted(B.iteritems()) + sage: sorted(six.iteritems(B)) [(3, (0, 0, 0)), (4, (0, 0, 1)), (5, (0, 0, 2)), (6, (0, 0, 3)), (7, (0, 0, 4)), (8, (0, 0, 5))] Reusable pieces:: @@ -1319,7 +1320,7 @@ def int_to_coord_dict(self): sage: q = Polyomino([(0,0), (0,1), (1,0), (1,1)]) sage: T = TilingSolver([p,q], box=[3,2], reusable=True) sage: B = T.int_to_coord_dict() - sage: sorted(B.iteritems()) + sage: sorted(six.iteritems(B)) [(0, (0, 0)), (1, (0, 1)), (2, (1, 0)), (3, (1, 1)), (4, (2, 0)), (5, (2, 1))] TESTS: diff --git a/src/sage/combinat/words/morphism.py b/src/sage/combinat/words/morphism.py index 99ff039d9af..87b1afc7d16 100644 --- a/src/sage/combinat/words/morphism.py +++ b/src/sage/combinat/words/morphism.py @@ -103,6 +103,7 @@ from sage.matrix.constructor import Matrix from sage.combinat.words.word import FiniteWord_class from sage.combinat.words.words import FiniteWords, FiniteOrInfiniteWords +import six def get_cycles(f, domain=None): r""" @@ -387,7 +388,7 @@ def __init__(self, data, domain=None, codomain=None): self._morph = {} dom_alph = list() - for (key,val) in data.iteritems(): + for (key,val) in six.iteritems(data): dom_alph.append(key) if val in codomain.alphabet(): self._morph[key] = codomain([val]) @@ -468,7 +469,7 @@ def _build_codomain(self, data): Finite words over {0, 1, 2} """ codom_alphabet = set() - for key,val in data.iteritems(): + for key,val in six.iteritems(data): try: it = iter(val) except Exception: @@ -484,7 +485,7 @@ def __hash__(self): sage: hash(WordMorphism('a->ab,b->ba')) # random 7211091143079804375 """ - return hash(tuple((k,v) for k,v in self._morph.iteritems())) ^ hash(self._codomain) + return hash(tuple((k,v) for k,v in six.iteritems(self._morph))) ^ hash(self._codomain) def __eq__(self, other): r""" @@ -597,7 +598,7 @@ def __str__(self): sage: str(s) 'a->ab, b->ba' """ - L = [str(lettre) + '->' + image.string_rep() for lettre,image in self._morph.iteritems()] + L = [str(lettre) + '->' + image.string_rep() for lettre,image in six.iteritems(self._morph)] return ', '.join(sorted(L)) def __call__(self, w, order=1, datatype='iter'): @@ -772,7 +773,7 @@ def __call__(self, w, order=1, datatype='iter'): length = 'finite' elif isinstance(w, FiniteWord_class): #Is it really a good thing to precompute the length? - length = sum(self._morph[a].length() * b for (a,b) in w.evaluation_dict().iteritems()) + length = sum(self._morph[a].length() * b for (a,b) in six.iteritems(w.evaluation_dict())) elif hasattr(w, '__iter__'): length = Infinity datatype = 'iter' @@ -947,7 +948,7 @@ def __mul__(self, other): sage: m * WordMorphism('') WordMorphism: """ - return WordMorphism(dict((key, self(w)) for (key, w) in other._morph.iteritems()), codomain=self.codomain()) + return WordMorphism(dict((key, self(w)) for (key, w) in six.iteritems(other._morph)), codomain=self.codomain()) def __pow__(self, exp): r""" @@ -1052,7 +1053,7 @@ def extend_by(self, other): raise TypeError("other (=%s) is not a WordMorphism"%other) nv = dict(other._morph) - for k,v in self._morph.iteritems(): + for k,v in six.iteritems(self._morph): nv[k] = v return WordMorphism(nv) @@ -1273,7 +1274,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 self._morph.iteritems()),codomain=self._codomain) + return WordMorphism(dict((key, w.reversal()) for (key, w) in six.iteritems(self._morph)),codomain=self._codomain) def is_empty(self): r""" @@ -2031,7 +2032,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 self._morph.iteritems())) + return WordMorphism(dict((key, w.conjugate(pos)) for (key, w) in six.iteritems(self._morph))) def has_left_conjugate(self): r""" diff --git a/src/sage/combinat/words/suffix_trees.py b/src/sage/combinat/words/suffix_trees.py index 173264256e5..cd06c4eabaf 100644 --- a/src/sage/combinat/words/suffix_trees.py +++ b/src/sage/combinat/words/suffix_trees.py @@ -11,6 +11,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** +import six from six import iteritems from sage.structure.sage_object import SageObject @@ -278,7 +279,7 @@ def transition_function(self, node, word): sage: w = Words([0,1])([0,1,0,1,1]) sage: t = SuffixTrie(w) sage: [t.transition_function(u,letter) == v \ - for ((u,letter),v) in t._transition_function.iteritems()] \ + for ((u,letter),v) in six.iteritems(t._transition_function)] \ == [True] * len(t._transition_function) True """