小编Fin*_*fin的帖子

在Python中反转排列

我是编程的新手,我正在尝试使用以下代码编写一个Python函数来查找{1,2,3,...,n}上的置换的逆矩阵:

def inv(str):
    result = []
    i = list(str).index(min(list(str)))
    while min(list(str)) < len(list(str)) + 1:
        list(str)[i : i + 1] = [len(list(str)) + 1]
        result.append(i + 1)
    return result
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用该函数时,inv('<mypermutation>')返回[].我错过了什么吗?Python是否因为某些语法原因跳过我的while循环而我不明白?我的google和stackoverflow都没有搜索我认为有用的主题.

python permutation

4
推荐指数
2
解决办法
4242
查看次数

标签 统计

permutation ×1

python ×1