python中安装特东顺序遍历字典中的所有键

 

 

>>> test1 = {"key8":"aaa","key4":"bbb","key9":"ccc","key3":"ddd","key2":"eee"}
>>> for i in test1.keys():
    print(i)

    
key8
key4
key9
key3
key2
>>> for i in sorted(test1.keys()):
    print(i)

    
key2
key3
key4
key8
key9
>>> for i in sorted(test1.keys(),reverse = True):
    print(i)

    
key9
key8
key4
key3
key2

 

posted @ 2020-12-31 22:42  小鲨鱼2018  阅读(83)  评论(0编辑  收藏  举报