python排序

from __future__ import division
a = [1,3,2,4]
print a
a.sort()
a.reverse()
print a
avg = sum(a)/len(a)
print '平均值:%f' % avg
dic = {'a':1 , 'b':2 , 'c': 3}
print dic
print '字典序:%s' % sorted(dic.iteritems(), key = lambda asd:asd[0] ,reverse = True)

[1, 3, 2, 4]
[4, 3, 2, 1]
平均值:2.500000
{'a': 1, 'c': 3, 'b': 2}
字典序:[('c', 3), ('b', 2), ('a', 1)]

你可能感兴趣的:(python)