Chinaunix首页 | 论坛 | 博客
  • 博客访问: 104500
  • 博文数量: 67
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-16 09:51
个人简介

啄木鸟专吃虫,故名啄木鸟。

分类: Python/Ruby

2014-06-06 17:30:45

有些看上去很简单的东西,不投入实践中的话,真的是不知道其细节是多么的精妙:
sorted(iterable[,cmp,[,key[,reverse=True]]])
usage:Return a new sorted list from the items in iterable.
一.interable是一个迭代器:
1.序列类型:list,str,tuple
2.非序列类型:dict,file
3.自定义的任何包含__iter__或者__getitem__()方法的类的对象:待试用
>>> s = [9,2,5,7]
>>> print sorted(s)#,sorted可以接受任何的interable,使用sorted返回一个新的排序列表
[2, 5, 7, 9]
>>> sorted({3: 'D', 1: 'B', 9: 'B', 4: 'E', 5: 'A'})
[1, 3, 4, 5, 9]
>>> print s#原始的s并未改变
[9, 2, 5, 7]
>>> s.sort()#使用列表的sort方法,则是改变列表本身
>>> print s#原始的s已经改变,排序好了。
[2, 5, 7, 9]
还没写完,明天继续
阅读(257) | 评论(0) | 转发(0) |
0

上一篇:安卓apk签名

下一篇:python的os.linesep

给主人留下些什么吧!~~