##// END OF EJS Templates
don’t modify dict keys while iterating through them...
MinRK -
Show More
@@ -47,22 +47,18 b' datetime.strptime("1", "%d")'
47 47 def rekey(dikt):
48 48 """Rekey a dict that has been forced to use str keys where there should be
49 49 ints by json."""
50 for k in dikt:
50 for k in list(dikt):
51 51 if isinstance(k, string_types):
52 ik=fk=None
52 nk = None
53 53 try:
54 ik = int(k)
54 nk = int(k)
55 55 except ValueError:
56 56 try:
57 fk = float(k)
57 nk = float(k)
58 58 except ValueError:
59 59 continue
60 if ik is not None:
61 nk = ik
62 else:
63 nk = fk
64 60 if nk in dikt:
65 raise KeyError("already have key %r"%nk)
61 raise KeyError("already have key %r" % nk)
66 62 dikt[nk] = dikt.pop(k)
67 63 return dikt
68 64
General Comments 0
You need to be logged in to leave comments. Login now