上代碼:java
from heapq import heappush,heappop from collections import OrderedDict def toTreeMap(paramMap): "將paramMap轉換爲java中的treeMap形式.將map的keys變爲heapq.建立有序字典." keys=paramMap.keys() heap=[] for item in keys: heappush(heap,item) sort=[] while heap: sort.append(heappop(heap)) resMap=OrderedDict() for key in sort: resMap[key]=paramMap.get(key) return resMap