标签:www items ack over color nbsp count dict reverse
1. 用count和dict. dict的存储是散乱的, 不方面打印.
2. 用sorted. 注意, 得到的是一个元组list, 而不再是dict.
dict_x = {} for item in list_all: dict_x[item] = list_all.count(item) sorted_x = sorted(dict_x.items(), key=operator.itemgetter(1), reverse=True) for k, v in sorted_x: print k, v
also can refer to:
http://www.saltycrane.com/blog/2007/09/how-to-sort-python-dictionary-by-keys/
http://stackoverflow.com/questions/613183/sort-a-python-dictionary-by-value
标签:www items ack over color nbsp count dict reverse
原文地址:http://www.cnblogs.com/qingyuanjushi/p/6739253.html