欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

马哥 今日小技巧 按键值升序排序 通过sorted结合key参数排序 有大用

dic={"name":"zs","age":18,"city":"深圳","tel":"1362626627"},按键值升序排序


通过sorted结合key参数排序,再重新组成字典


dic = {"name":"zs","age":18,"city":"深圳","tel":"1362626627"}


tmp = sorted(dic.items(), key=lambda x: x[0])


print(dict(tmp))


来自  http://ke.magedu.com/article/113

普通分类: