首页 > 解决方案 > 如何在python的排列中找到最大的数字?

问题描述

我想从排列中提取最大的数字。我现在正在使用组模块,所以下面代码中的输出应该是 15


from groups import *

a = Perm((1, 2, 3), (4, 15, 6), (7, 8, 9))

max([x for x in a])

标签: pythonmathpermutationfinite-group-theory

解决方案


如果只想找到最大值,我并没有得到你想要的这些排列。但是你试试这个-

    from itertools import permutations 
    perm = permutations([1, 2, 3, 4, 15, 6, 7, 8, 9]) 
    for i in list(perm): 
    print (max(i)) 

这段代码将始终 15 作为输出。


推荐阅读