原始的字典键都是整数。有什么更简短的方法可以将所有整数键转换为字符串?
original = {1:{},2:{101:"OneZeroOne",202:"TwoZeroTwo"}}
result = {}
for key in original:
if not key in result:
result[str(key)]={}
for i, value in original[key].items():
result[str(key)][str(i)] = value
print result
打印:
{'1': {}, '2': {'202': 'TwoZeroTwo', '101': 'OneZeroOne'}}
...更短的方法...
- 执行时间还是代码行数更少? - wwii