1.字典
dict.items() 以列表的形式返回
如果想遍歷字典,應該for key, value in dict.items()這樣做。
2.math.gcd(x, y)求兩個數的最大公約數
3.dict.get(x)返回鍵,找到x節點,然後返回,如果找不到,返回None
4.map是一個迭代器,要和list搭配使用。如list(map(int, str))
s1 = 15
s2 = 20
a = list(map(int, str(s1) + str(s2)))
print(a)[1, 5, 2, 0]
5.heapq模塊裏對堆元素的添加和刪除
添加:heapq.heappush(heap, x)
刪除:heapq.heappop(heap)
堆頂元素爲heap[0]
6.s = "abc";不能使用s[0] = "c" 這樣的用法,但是s += "d"可以
7.有一個易錯的點,就是位運算時,flag = 1, flag <<= 1, n & flag = flag纔對,而不是n&flag=1
8.32位最大正數2 ** 31 - 1,最小數爲 -2 ** 31
9.短路特性:
left and right,如果left爲假,right不運行;如果left爲真,結果取決於right
left or right,如果left爲假,取決於right;如果left爲真,right不運行
例如 print(0 and 8) ==>0 print(1 and 8) ==> 8
10.