distance = {9149: 0, 9150: 26, 9151: 24, 9152: 24, 9153: 24, 9154: 27, 9155: 25, 9156: 30, 9158: 20, 9159: 22, 9160: 25, 9161: 21, 9163: 25, 9164: 23, 9165: 25, 9166: 30, 9167: 20, 9169: 25, 9170: 24, 9171: 23, 9172: 25, 9173: 24, 9174: 29, 9176: 27, 9177: 25, 9179: 25, 9180: 32, 9181: 25, 9182: 25, 9183: 24, 9184: 25, 9185: 25, 9186: 25, 9188: 26, 9189: 20, 9190: 25, 9191: 27, 9193: 24, 9195: 24, 9196: 24, 9197: 23, 9198: 25, 9199: 25, 9201: 24, 9202: 25, 9203: 24, 9204: 25, 9205: 25, 9206: 25, 9208: 24, 9209: 22, 9210: 23, 9211: 22, 9212: 23, 9215: 25, 9217: 28, 9218: 25, 9219: 25, 9220: 33, 9221: 21, 9222: 25, 9224: 25, 9225: 25, 9226: 25, 9227: 24, 9228: 28, 9230: 22, 9231: 25, 9232: 24, 9233: 25, 9235: 24, 9236: 21, 9237: 22, 9238: 24, 9239: 22, 9240: 20, 9241: 24, 9242: 23, 9245: 22, 9248: 23, 9249: 22, 9250: 22, 9251: 23, 9252: 22, 9253: 22, 9254: 19, 9255: 23, 9256: 21, 9257: 23, 9258: 25, 9259: 23, 9260: 24, 9261: 22, 9263: 22, 9264: 23, 9265: 22, 9266: 22, 9267: 23, 9268: 25, 9269: 22, 9270: 22, 9271: 21, 9274: 24, 9276: 24, 9277: 25, 9279: 28, 9282: 21, 9283: 21, 9285: 22, 9286: 24, 9287: 24, 9289: 24, 9290: 25, 9292: 22, 9293: 22, 9296: 23, 9298: 21, 9299: 23, 9300: 22, 9302: 22, 9303: 25, 9304: 24, 9306: 25, 9307: 25, 9308: 22, 9311: 23, 9312: 25, 9315: 22, 9316: 24, 9317: 23, 9318: 22, 9320: 21, 9321: 28, 9324: 22, 9325: 21, 9328: 22, 9329: 22, 9330: 21, 9331: 25, 9332: 21}
print(distance)
#按value排序
print(sorted(distance.items(),key=lambda item:item[1])) #反序
#print(sorted(distance.items(),key=lambda item:item[1],reverse=True)) #按Key排序
#print(sorted(distance.items(),key=lambda item:item[0])) #[(9149, 0), (9254, 19), (9158, 20), (9167, 20), (9189, 20), (9240, 20), (9161, 21), (9221, 21), (9236, 21), (9256, 21), (9271, 21), (9282, 21), (9283, 21), (9298, 21), (9320, 21), (9325, 21), (9330, 21), (9332, 21), (9159, 22), (9209, 22), (9211, 22), (9230, 22), (9237, 22), (9239, 22), (9245, 22), (9249, 22), (9250, 22), (9252, 22), (9253, 22), (9261, 22), (9263, 22), (9265, 22), (9266, 22), (9269, 22), (9270, 22), (9285, 22), (9292, 22), (9293, 22), (9300, 22), (9302, 22), (9308, 22), (9315, 22), (9318, 22), (9324, 22), (9328, 22), (9329, 22), (9164, 23), (9171, 23), (9197, 23), (9210, 23), (9212, 23), (9242, 23), (9248, 23), (9251, 23), (9255, 23), (9257, 23), (9259, 23), (9264, 23), (9267, 23), (9296, 23), (9299, 23), (9311, 23), (9317, 23), (9151, 24), (9152, 24), (9153, 24), (9170, 24), (9173, 24), (9183, 24), (9193, 24), (9195, 24), (9196, 24), (9201, 24), (9203, 24), (9208, 24), (9227, 24), (9232, 24), (9235, 24), (9238, 24), (9241, 24), (9260, 24), (9274, 24), (9276, 24), (9286, 24), (9287, 24), (9289, 24), (9304, 24), (9316, 24), (9155, 25), (9160, 25), (9163, 25), (9165, 25), (9169, 25), (9172, 25), (9177, 25), (9179, 25), (9181, 25), (9182, 25), (9184, 25), (9185, 25), (9186, 25), (9190, 25), (9198, 25), (9199, 25), (9202, 25), (9204, 25), (9205, 25), (9206, 25), (9215, 25), (9218, 25), (9219, 25), (9222, 25), (9224, 25), (9225, 25), (9226, 25), (9231, 25), (9233, 25), (9258, 25), (9268, 25), (9277, 25), (9290, 25), (9303, 25), (9306, 25), (9307, 25), (9312, 25), (9331, 25), (9150, 26), (9188, 26), (9154, 27), (9176, 27), (9191, 27), (9217, 28), (9228, 28), (9279, 28), (9321, 28), (9174, 29), (9156, 30), (9166, 30), (9180, 32), (9220, 33)]
#{9149: 0, 9150: 26, 9151: 24, 9152: 24, 9153: 24, 9154: 27, 9155: 25, 9156: 30, 9158: 20, 9159: 22, 9160: 25, 9161: 21, 9163: 25, 9164: 23, 9165: 25, 9166: 30, 9167: 20, 9169: 25, 9170: 24, 9171: 23, 9172: 25, 9173: 24, 9174: 29, 9176: 27, 9177: 25, 9179: 25, 9180: 32, 9181: 25, 9182: 25, 9183: 24, 9184: 25, 9185: 25, 9186: 25, 9188: 26, 9189: 20, 9190: 25, 9191: 27, 9193: 24, 9195: 24, 9196: 24, 9197: 23, 9198: 25, 9199: 25, 9201: 24, 9202: 25, 9203: 24, 9204: 25, 9205: 25, 9206: 25, 9208: 24, 9209: 22, 9210: 23, 9211: 22, 9212: 23, 9215: 25, 9217: 28, 9218: 25, 9219: 25, 9220: 33, 9221: 21, 9222: 25, 9224: 25, 9225: 25, 9226: 25, 9227: 24, 9228: 28, 9230: 22, 9231: 25, 9232: 24, 9233: 25, 9235: 24, 9236: 21, 9237: 22, 9238: 24, 9239: 22, 9240: 20, 9241: 24, 9242: 23, 9245: 22, 9248: 23, 9249: 22, 9250: 22, 9251: 23, 9252: 22, 9253: 22, 9254: 19, 9255: 23, 9256: 21, 9257: 23, 9258: 25, 9259: 23, 9260: 24, 9261: 22, 9263: 22, 9264: 23, 9265: 22, 9266: 22, 9267: 23, 9268: 25, 9269: 22, 9270: 22, 9271: 21, 9274: 24, 9276: 24, 9277: 25, 9279: 28, 9282: 21, 9283: 21, 9285: 22, 9286: 24, 9287: 24, 9289: 24, 9290: 25, 9292: 22, 9293: 22, 9296: 23, 9298: 21, 9299: 23, 9300: 22, 9302: 22, 9303: 25, 9304: 24, 9306: 25, 9307: 25, 9308: 22, 9311: 23, 9312: 25, 9315: 22, 9316: 24, 9317: 23, 9318: 22, 9320: 21, 9321: 28, 9324: 22, 9325: 21, 9328: 22, 9329: 22, 9330: 21, 9331: 25, 9332: 21}

Python对字典(directory)按key和value排序的更多相关文章

  1. python 根据字典中的key,value进行排序

    #coding=utf-8 import requests,json,collections,base64,datetime def sort(datas): data=json.dumps(data ...

  2. python 对字典分别按照key值、value值进行排序

    1.sorted函数首先介绍sorted函数,sorted(iterable,key,reverse),sorted一共有iterable,key,reverse这三个参数. 其中iterable表示 ...

  3. python 合并字典,相同 key 的 value 如何相加?

    x = { 'apple': 1, 'banana': 2 } y = { 'banana': 10, 'pear': 11 } 需要把两个字典合并,最后输出结果是: { 'apple': 1, 'b ...

  4. iOS_字典数组 按key分组和排序

    int main(int argc, const charchar * argv[]) { @autoreleasepool { // 1.定义一个测试的字典数组 NSMutableArray *di ...

  5. Python对字典分别按键(key)和值(value)进行排序

    使用sorted函数进行排序 sorted(iterable,key,reverse),sorted一共有iterable,key,reverse这三个参数;其中iterable表示可以迭代的对象,例 ...

  6. python 字典操作提取key,value

    python 字典操作提取key,value dictionaryName[key] = value 1.为字典增加一项  2.访问字典中的值  3.删除字典中的一项  4.遍历字典  5.字典遍历的 ...

  7. python获取字典的key列表

    获取字典的所有key: # !/usr/bin/python3.4 # -*- coding: utf-8 -*- b = { 'video':0, 'music':23 } print(list(b ...

  8. python学习笔记 - for循环: 遍历字典, 分别打印key, value, key:value

    #遍历字典, 分别打印key, value, key:value emp = {'name':'Tom', 'age':20, 'salary' : 8800.00} for k in emp.key ...

  9. python中字典以key排序,以value排序。以及通过value找key的方式

    1.sorted函数首先介绍sorted函数,sorted(iterable,key,reverse),sorted一共有iterable,key,reverse这三个参数. 其中iterable表示 ...

  10. python 数据类型 ----字典

    字典由一对key:value 组成的 python中常用且重量级的数据类型 1. key , keys, values 字典由一对key:value 组成的 python中常用且重量级的数据类型 1. ...

随机推荐

  1. MYSQL内存评估

    ### MySQL Memory Calculator Procedure ### http://kedar.nitty-witty.com/blog/calculte-mysql-memory-us ...

  2. nginx location 配置详解 【转载,整理】

    http://www.nginx.cn/115.html NGINX location 配置参考:http://www.cnblogs.com/zlingh/p/6288994.html https: ...

  3. Java Date and Calendar examples

    Java Date and Calendar examples This tutorial shows you how to work with java.util.Date and java.uti ...

  4. Android SDK Manager详解

    Android基础知识——Android SDK Manager详解   做Android开发时,免不了使用Android SDK Manager,安装需要的sdk版本.buildTools版本等等. ...

  5. Java数据结构和算法(六):前缀、中缀、后缀表达式

    前面我们介绍了三种数据结构,第一种数组主要用作数据存储,但是后面的两种栈和队列我们说主要作为程序功能实现的辅助工具,其中在介绍栈时我们知道栈可以用来做单词逆序,匹配关键字符等等,那它还有别的什么功能吗 ...

  6. 标准差(Standard Deviation) 和 标准误差(Standard Error)

    本文摘自 Streiner DL.Maintaining standards: differences between the standard deviation and standarderror ...

  7. 快速开方法(c语言)译文

    人们最早就在Quake3源代码中发现了类似如下的C代码,它可以快速的求1/sqrt(x),在3D图形向量计算方面应用很广. float invSqrt(float x) { float xhalf = ...

  8. 对于在Android Studio 的 build.gradle 中的默认applicationId 要不要写呢?

    起因 刚完成一个版本的开发.刚上Google play 就有用户反映无法更新应用.错误代码为:Can't install app "****" can' be installed. ...

  9. javascript <a> 标签打开相对路径,绝对路径

    <a>标签中的href中,如果你写一个路径默认是以相对路径打开的,加上"http://" 消息头那就可以打开绝对路径 html: <a href=javascri ...

  10. Android Lock Pattern 图案解锁

    参考链接:http://www.cnblogs.com/dyingbleed/archive/2012/12/03/2800007.html http://blog.csdn.net/way_ping ...