#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import operator
c = {} #dict
c[3] = 4
c[13] = 1
c[5] = 10
c[7] = 2
print c
print sorted(c.iteritems(), key=operator.itemgetter(0), reverse=True)
#第一个参数为可迭代类型,第二个是以dict的第一项为基础排序,第三个是升序排列,flase默认为降序排列。
print sorted(c.iteritems(), key=operator.itemgetter(1), reverse=True)
Python sorted 函数
最新推荐文章于 2024-03-29 15:03:01 发布