Skip to content

Commit 7af4629

Browse files
committed
python3 accumulate
1 parent cde0457 commit 7af4629

File tree

1 file changed

+5
-1
lines changed
  • docs/19_python内置常用算法和数据结构

1 file changed

+5
-1
lines changed

docs/19_python内置常用算法和数据结构/builtins.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ MAXINT = (1<<63) - 1
6262
MININT = ~MAXINT
6363
```
6464

65-
# python list/dict 排序技巧
65+
# python list/dict 排序等技巧
6666

6767
```py
6868
# python 根据 key,value 排序字典
@@ -99,6 +99,10 @@ sorted(nums, key= cmp_to_key(lambda a,b: b-a) ) # [5, 4, 3, 2, 1]
9999

100100
# 一行代码判断列表是否有序
101101
issorted = all(l[i] <= l[i+1] for i in range(len(l) - 1))
102+
103+
# python3 一行代码求前缀和
104+
from itertools import accumulate
105+
presums = list(accumulate([1,2,3])) # [1, 3, 6]
102106
```
103107

104108
# 链表题目调试函数

0 commit comments

Comments
 (0)