Permutation返回True或False python

-3 python permutation

我正在尝试创建一个函数isPerm(P),True如果它是一个排列,则返回,False否则.

到目前为止我有:

def isPerm(P):
    if len(P) == list(range(P)):
        return True
    else:
        return False
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很棒.

the*_*eye 6

我能想到的最简单的方法就是使用 Counter

from collections import Counter

def isPerm(P, Q):
    return Counter(P) == Counter(Q)

print isPerm("oolegg", "google")
Run Code Online (Sandbox Code Playgroud)

产量

True
Run Code Online (Sandbox Code Playgroud)