Skip to content

Commit

Permalink
一行代码判断元素是否在矩阵中
Browse files Browse the repository at this point in the history
  • Loading branch information
PegasusWang committed May 15, 2022
1 parent 9bf19c5 commit 4eb9fe7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/19_python内置常用算法和数据结构/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ presums = list(accumulate([1,2,3])) # [1, 3, 6]

# 一行代码求矩阵元素总和 https://stackoverflow.com/questions/10713150/how-to-sum-a-2d-array-in-python
allsum = sum(map(sum, matrix)) # 或者 allsum = sum((sum(row) for row in matrix))
# 一行代码判断一个元素是否在矩阵中,比如判断 1 是否在矩阵matrix中
any(1 in row for row in matrix)
```

# python dict 技巧
Expand Down

0 comments on commit 4eb9fe7

Please sign in to comment.