下载huhamhire-hosts
要用到curse 模块
到http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses
下载curses-2.2.win32-py2.7.exe
python的标准库学习:
https://python-documentation-cn.readthedocs.org/en/latest/library/index.html
build-in modules(write in C)
python列表排序:
http://gaopenghigh.iteye.com/blog/1483864
List的sort方法(或sorted内建函数)的用法
https://wiki.python.org/moin/HowTo/Sorting/
sorted(data, cmp=None, key=None, reverse=False)
1. 对由tuple组成的List排序
- >>> students = [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10),]
- >>> sorted(students, key=lambda student : student[2]) # sort by age
- [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
- >>> sorted(students, cmp=lambda x,y : cmp(x[2], y[2])) # sort by age
- [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
- >>> from operator import itemgetter, attrgetter
- >>> sorted(students, key=itemgetter(2))
- >>> sorted(students, key=itemgetter(1,2)) # sort by grade then by age
- [('john', 'A', 15), ('dave', 'B', 10), ('jane', 'B', 12)]
- >>> d = {'data1':3, 'data2':1, 'data3':2, 'data4':4}
- >>> sorted(d.iteritems(), key=itemgetter(1), reverse=True)
- [('data4', 4), ('data1', 3), ('data3', 2), ('data2', 1)]
yield
http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/
使用的产生器,要使用next函数获取每次产生的返回值。最后会引起一个StopIteration的错误。一般使用for 循环获取每个值。
zip() in conjunction with the * operator can be used to unzip alist:
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> zipped
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zipped)
>>> x == list(x2) and y == list(y2)
True
operator 模块为python提供了一个“功能性"的标准操作符接口,当使用map 或filter sorted 一类函数时,operator模块中的函数可以替换一些lambda函数。
types 模块包含了标准解析器定义的所有类型的类型对象。
=============================================================================================================
Python for Data Analysis