diff --git a/IPython/utils/jsonutil.py b/IPython/utils/jsonutil.py index b16f14d..a7693ca 100644 --- a/IPython/utils/jsonutil.py +++ b/IPython/utils/jsonutil.py @@ -47,22 +47,18 @@ datetime.strptime("1", "%d") def rekey(dikt): """Rekey a dict that has been forced to use str keys where there should be ints by json.""" - for k in dikt: + for k in list(dikt): if isinstance(k, string_types): - ik=fk=None + nk = None try: - ik = int(k) + nk = int(k) except ValueError: try: - fk = float(k) + nk = float(k) except ValueError: continue - if ik is not None: - nk = ik - else: - nk = fk if nk in dikt: - raise KeyError("already have key %r"%nk) + raise KeyError("already have key %r" % nk) dikt[nk] = dikt.pop(k) return dikt