python - 如何在python的排列中找到最大的数字?
问题描述
我想从排列中提取最大的数字。我现在正在使用组模块,所以下面代码中的输出应该是 15
from groups import *
a = Perm((1, 2, 3), (4, 15, 6), (7, 8, 9))
max([x for x in a])
解决方案
如果只想找到最大值,我并没有得到你想要的这些排列。但是你试试这个-
from itertools import permutations
perm = permutations([1, 2, 3, 4, 15, 6, 7, 8, 9])
for i in list(perm):
print (max(i))
这段代码将始终 15 作为输出。
推荐阅读
- scala - Scalatest:组合断言
- ios - 如何在 iOS Web 应用程序中保存凭据/会话?
- python - 是否可以在单个 GRPC 服务器上运行同一服务的多个实例?
- html - 在html中居中文本,同时保持左对齐?
- transactions - 转换为 .net core 3.1 后,当前的 TransactionScope 已完成错误
- file - 在 go 中逐字节处理文件
- mysql - MySQL 使用 WHERE 的结果更新条件(已解决)
- r - 删除重复项,同时优先考虑 R 中不同列中的特定值
- javascript - 在 React Native 中使用异步组件的 Redux
- python - 为什么 numpy ifft 不返回我的原始光谱?