我需要检查一个字符串是否包含一组字符,并且它们需要显示正确的次数.
string1 = "somestring"
string2 = "thestrings"
characters = "egimnorsst" # Note that there are two 's' characters here
does_string_contain(string1, characters) # True
does_string_contain(string2, characters) # False
Run Code Online (Sandbox Code Playgroud)
只需对它们进行排序和比较
>>> sorted("egimnorsst") == sorted("somestring")
True
Run Code Online (Sandbox Code Playgroud)