Tag: 字典

Python让字典保持有序

Jackey Python 688 次浏览 ,
# 让字典保持有序 from mrjob.py2 import xrange from pip._vendor.distlib.compat import raw_input d = {} d['Jim'] = (1, 35) d['Leo'] = (2, 37) d['Bob'] = (3, 40) for k in d: print(k) from collections i...

Python根据字典中的值大小排序

Jackey Python 1,185 次浏览 , ,
from random import randint d = {x: randint(60, 100) for x in 'xyzabc'} print(d) # 将字典转化为元组, 第一种方式 d2 = list(zip(d.values(), d.keys())) print(sorted(d2)) # 第二种方式 d3 = d.items() print(d3) ...
Go