Python学习笔记

Python 编码

  1. a = u'ab'
    b = "ab"
    如何互转?
  2. unicode声明
# -*- coding: utf-8 -*-
  1. join unicode

  2. 用chardet检测编码格式

Python编码

类型

python的函数特性

  1. map

pyquery

https://pypi.python.org/pypi/pyquery
api : http://pyquery.readthedocs.org/en/latest/api.html

TypeError: Type 'unicode' cannot be serialized.

给两个list,一个是word list, 一个是prefix list return 所有的word that have the prefix 例子: word list = [“a", "abc", "dz", "dda], prefix list = ["ab", "dd"] return ["abc", "dda"]

Python干货精选 http://baoz.me/446252
当我说我会Python时,实际上我会了什么?

遍历目录

os.walk

import os,sys
for root, dirs, files in os.walk("."):
for f in files:
fullpath = "%s/%s" % (root, f)
if fullpath.endswith("java"):
print fullpath
#os.system("dos2unix " + fullpath)
temp = fullpath[:-1]
#command = "expand -t 4 " + fullpath + " > " + temp
command = "rm -rf " + fullpath
command = "sed -i 's/ *$//' " + fullpath
#print command
os.system(command)

性能:

High Performance Python: Practical Performant Programming for Humans

profile:

7 个测量 Python 脚本和控制内存以及 CPU 使用率的技巧

random

常用模块

bitarray : bit操作

profile:
memory_profiler

awesome-python : https://github.com/vinta/awesome-python

python-books:

how to think like a computer scientist : http://www.greenteapress.com/thinkpython/thinkCSpy.pdf

算法
python 字典(dict)按键和值排序

http://www.cnpythoner.com/post/266.html

Python数据结构

集合

https://docs.python.org/2/library/stdtypes.html#set

hash表:

dict:
https://docs.python.org/2/library/stdtypes.html#dict

高阶函数:

functools: https://docs.python.org/2/library/functools.html

函数嵌套:
http://effbot.org/pyfaq/how-do-you-make-a-higher-order-function-in-python.htm

列表

连接列表
[1 ,2, 3 ] + [4, 5, 6] = [1, 2, 3, 4, 5, 6]

列表生成

http://www.cnblogs.com/moinmoin/archive/2011/03/10/lsit-comprehensions-generators.html

Pip

hash not match: http://stackoverflow.com/questions/16025788/why-does-pip-fail-with-bad-md5-hash-for-package#

你可能感兴趣的:(Python学习笔记)