增加列表数据
- list.append(x) , O(1),or O(n) (when storage is not enough and data needs to be moved)
- list.insert(index, x), O(N), 后面的元素往后移(if we need Frequent insertion/deletion Not frequent random access We shouldn’t use arrays)
- 查找
- list[index], O(1)
- 修改
- list[index] = x,O(1)
排序
- list.sort(),在原列表上进行排序,O(N*logN)
- sorted(list),返回排序后的列表,但是原列顺序不变,O(N*logN)
其他常用操作
- list.reverse(),O(N)
- len(list), O(1)
- list(range(5)),O(N)
- max(list), min(list), sum(list),O(N)