python的性能

1、Use xrange instead of range.

2、"".join(string) is better than + or +=

3、while 1 is faster than while True

4、 list comphrension > for loop > while loop

Use Map, Reduce and Filter instead of for loop where ever possible.

5、for checking 'a in b', dict or set is better than list/tuple.

6、if you need manipulations on both ends of a list, use deque.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章