小tips:(1)print不换行:print(x, end="")
(2)[::-1]:切片 倒序
(3)s='' s[0]=error s[0:]='' s[10:]=''
4.
str.isupper() str.islower()
str.istitle()  如果字符串中所有的单词拼写首字母是否为大写,且其他字母为小写则返回 True,否则返回 False.
str.capitalize()#此方法返回的字符串只有它的第一个字符大写的副本

5.
collection包 Counter类

6.
Counter 间的数学集合操作
>>> c = Counter(a=3, b=1, c=5)
>>> d = Counter(a=1, b=2, d=4)
>>> c + d # counter相加, 相同的key的value相加
Counter({'c': 5, 'a': 4, 'd': 4, 'b': 3})
>>> c - d # counter相减, 相同的key的value相减,只保留正值得value
Counter({'c': 5, 'a': 2})
>>> c & d # 交集: 取两者都有的key,value取小的那一个
Counter({'a': 1, 'b': 1})
>>> c | d # 并集: 汇聚所有的key, key相同的情况下,取大的value
Counter({'c': 5, 'd': 4, 'a': 3, 'b': 2})

7.
str.lower()不改变str的值,而是产生新的string
list.sort()则改变了list的值

8.
python中初始化二维数组
[[0 for col in range(5)] for row in range(3)]
http://blog.csdn.net/justheretobe/article/details/7632487

9.
str.strip([chars])
返回移除字符串头尾指定的字符生成的新字符串

10.
正则表达式
http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143193331387014ccd1040c814dee8b2164bb4f064cff000

11.
AttributeError: 'list' object has no attribute 'find'

12.
dict.get(key, default=None)
返回指定键的值,如果值不在字典中返回默认值None

13.
dict.get(key, default=None)
该方法返回一个给定键的值。如果键不可用,则返回默认值为None

14,
list.insert(index, obj)
index -- 对象 obj 需要插入的索引位置。
obj -- 要插入列表中的对象。

15.
sorted(people, key=lambda x: (-x[0], x[1]))
貌似是按x[0]降序 若x[0]相等则按x[1]升序

16.
515题
def findValueMostElement(self, root):
maxes = []
row = [root]
while any(row):
maxes.append(max(node.val for node in row))
row = [kid for node in row for kid in (node.left, node.right) if kid]
return maxes
any 如果iterable的任何元素不为0、''、False,all(iterable)返回True。如果iterable为空,返回False

17.
set不是append是 add

18.
sort或者sorted cmp定义规则
http://gaopenghigh.iteye.com/blog/1483864

19.
divmod(a,b)方法返回的是a//b(除法取整)以及a对b的余数
返回结果类型为tuple

20.

reduce( func, seq[, init] )

21.

tuple = ('hi', )   ## size 1 tuple

22.

hash = {}
hash['word'] = 'garfield'
hash['count'] = 42
s = 'I want %(count)d copies of %(word)s' % hash  # %d for int, %s for string
# 'I want 42 copies of garfield'

格式化输出

 

23. del

var = 6
  del var  # var no more!
  list = ['a', 'b', 'c', 'd']
  del list[0]     ## Delete first element
  del list[-2:]   ## Delete last two elements
  print list      ## ['b']
  dict = {'a':1, 'b':2, 'c':3}
  del dict['b']   ## Delete 'b' entry
  print dict      ## {'a':1, 'c':3}

 

24. read() 、readlines()、readline()

http://www.cnblogs.com/hanggegege/p/5926549.html

25.

Python3中/表示真除,%表示取余,//表示地板除(结果取整)

26.

assert a>b, xxxx

if true nothing happen;if false, 报错XXXX

27.

CS61A lecture4

python3 -m doctest -i ex.py

https://my.oschina.net/lionets/blog/268542

posted on 2017-03-15 22:37  sys_c  阅读(152)  评论(0编辑  收藏  举报