You could do OrderedDict = dict in line 42 and then just use OrderedDict here without the if