桶排序-py

http://blog.chinaunix.net/uid-20775448-id-4222915.html

看了<啊哈算法>第一节,排序从小到大自己实现了.

从大到小,搜集了下资料.看了下.这个url不错.

重点:

Python实例:

1

2

3

4

5

6

>>> list = [2,5,8,9,3]  

>>> list  

[2,5,8,9,3]  

>>> list.sort()  

>>> list  

[2, 3, 5, 8, 9]

方法2.用序列类型函数sorted(list)进行排序(从2.4开始)

Python实例:

1

2

3

4

5

>>> list = [2,5,8,9,3]  

>>> list  

[2,5,8,9,3]  

>>> sorted(list)  

[2, 3, 5, 8, 9]

实例1:正向排序

1

2

3

4

>>>L = [2,3,1,4]

>>>L.sort()

>>>L

>>>[1,2,3,4]

实例2:反向排序

1

2

3

4

>>>L = [2,3,1,4]

>>>L.sort(reverse=True)

>>>L

>>>[4,3,2,1]

原文地址:https://www.cnblogs.com/iiiiher/p/5566354.html