Skip to content

Commit 139bd30

Browse files
committed
some changes about dict in combinat (ruff PLC0206)
1 parent 1be0a58 commit 139bd30

File tree

13 files changed

+40
-48
lines changed

13 files changed

+40
-48
lines changed

src/sage/combinat/binary_recurrence_sequences.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ def pthpowers(self, p, Bound):
729729

730730
# Check how long each element has persisted, if it is for at least 7 cycles,
731731
# then we check to see if it is actually a perfect power
732-
for i in Possible_count:
733-
if Possible_count[i] == 7:
732+
for i, pci in Possible_count.items():
733+
if pci == 7:
734734
n = Integer(i)
735735
if n < Bound:
736736
if _is_p_power(self(n), p):

src/sage/combinat/chas/wqsym.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,12 +986,12 @@ def union(X, Y):
986986
cur = {data[0]: 1}
987987
for B in data[1:]:
988988
ret = {}
989-
for A in cur:
989+
for A, curA in cur.items():
990990
for C in ShuffleProduct_overlapping(A, B, element_constructor=OSP, add=union):
991991
if C in ret:
992-
ret[C] += cur[A]
992+
ret[C] += curA
993993
else:
994-
ret[C] = cur[A]
994+
ret[C] = curA
995995
cur = ret
996996

997997
# Return the result in the X basis

src/sage/combinat/designs/bibd.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,14 +1277,14 @@ def BIBD_5q_5_for_q_prime_power(q):
12771277

12781278
d = (q-1)//4
12791279
B = []
1280-
F = FiniteField(q,'x')
1280+
F = FiniteField(q, 'x')
12811281
a = F.primitive_element()
1282-
L = {b:i for i,b in enumerate(F)}
1283-
for b in L:
1284-
B.append([i*q + L[b] for i in range(5)])
1282+
L = {b: i for i, b in enumerate(F)}
1283+
for b, Lb in L.items():
1284+
B.append([i*q + Lb for i in range(5)])
12851285
for i in range(5):
12861286
for j in range(d):
1287-
B.append([ i*q + L[b ],
1287+
B.append([ i*q + Lb,
12881288
((i+1) % 5)*q + L[ a**j+b ],
12891289
((i+1) % 5)*q + L[-a**j+b ],
12901290
((i+4) % 5)*q + L[ a**(j+d)+b],

src/sage/combinat/designs/difference_family.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def is_difference_family(G, D, v=None, k=None, l=None, verbose=False):
292292

293293
# Normalized number of occurrences added to counter
294294
stabi = len(stab[i])
295-
for gg in tmp_counter:
296-
counter[gg] += tmp_counter[gg]//stabi
295+
for gg, tmp_gg in tmp_counter.items():
296+
counter[gg] += tmp_gg // stabi
297297

298298
# Check the counter and report any error
299299
too_few = []

src/sage/combinat/parallelogram_polyomino.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ def __call__(self, *get_values, **options):
311311
{'diagram': 'diagram representation',
312312
'list': 'list representation'}}
313313
"""
314-
for key in options:
315-
value = options[key]
314+
for key, value in options.items():
316315
self.__setitem__(key, value)
317316
for key in get_values:
318317
return self.__getitem__(key)

src/sage/combinat/posets/incidence_algebras.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ def __init__(self, I, prefix='R') -> None:
456456
for i in self._ambient.basis().keys():
457457
S = P.subposet(P.interval(*i))
458458
added = False
459-
for k in EC:
459+
for k, ECk in EC.items():
460460
if S._hasse_diagram.is_isomorphic(k._hasse_diagram):
461-
EC[k].append(i)
461+
ECk.append(i)
462462
added = True
463463
break
464464
if not added:

src/sage/combinat/posets/posets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,10 +2058,10 @@ def plot(self, label_elements=True, element_labels=None,
20582058
'cover_colors': 'edge_colors',
20592059
'cover_style': 'edge_style',
20602060
'border': 'graph_border'}
2061-
for param in rename:
2061+
for param, value in rename.items():
20622062
tmp = kwds.pop(param, None)
20632063
if tmp is not None:
2064-
kwds[rename[param]] = tmp
2064+
kwds[value] = tmp
20652065

20662066
heights = kwds.pop('heights', None)
20672067
if heights is None:

src/sage/combinat/rigged_configurations/kleber_tree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ def latex_options(self, **options):
666666
if not options:
667667
from copy import copy
668668
return copy(self._latex_options)
669-
for k in options:
670-
self._latex_options[k] = options[k]
669+
for key, value in options.items():
670+
self._latex_options[key] = value
671671

672672
def _latex_(self):
673673
r"""

src/sage/combinat/root_system/weyl_characters.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,9 @@ def _demazure_helper(self, dd, word='long', debug=False):
761761
next[mu] = next.get(mu, 0) - accum[v]
762762
if debug:
763763
print(" mu=%s, next[mu]=%s" % (mu, next[mu]))
764-
accum = {}
765-
for v in next:
766-
accum[v] = next[v]
767-
ret = {}
768-
for v in accum:
769-
if accum[v]:
770-
ret[self._space.from_vector_notation(v, style='coroots')] = accum[v]
771-
return ret
764+
accum = dict(next)
765+
return {self._space.from_vector_notation(v, style='coroots'): val
766+
for v, val in accum.items() if val}
772767

773768
@cached_method
774769
def _weight_multiplicities(self, x):

src/sage/combinat/sf/classical.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
from . import jack
3131
from . import orthotriang
3232

33-
translate = {'monomial':'MONOMIAL', 'homogeneous':'HOMSYM', 'powersum':'POWSYM', 'elementary':'ELMSYM', 'Schur':'SCHUR'}
33+
translate = {'monomial': 'MONOMIAL',
34+
'homogeneous': 'HOMSYM',
35+
'powersum': 'POWSYM',
36+
'elementary': 'ELMSYM',
37+
'Schur': 'SCHUR'}
3438

3539
conversion_functions = {}
3640

@@ -55,11 +59,11 @@ def init():
5559
s[1, 1, 1, 1] - s[2, 1, 1] + 2*s[2, 2] - s[3, 1] + s[4]
5660
"""
5761
import sage.libs.symmetrica.all as symmetrica
58-
for other_basis in translate:
59-
for basis in translate:
62+
for other_basis, other_name in translate.items():
63+
for basis, name in translate.items():
6064
try:
6165
conversion_functions[(other_basis, basis)] = getattr(symmetrica,
62-
't_{}_{}'.format(translate[other_basis], translate[basis]))
66+
f't_{other_name}_{name}')
6367
except AttributeError:
6468
pass
6569

0 commit comments

Comments
 (0)