Skip to main content
 首页 » 编程设计

Python之字符串是否包含另一个字符串中的所有字符

2025年05月04日25mate10pro

<分区>

我需要检查一个字符串是否包含一组字符,并且它们需要出现正确的次数。

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