2024-06-01 10:26:46 发布
网友
string = 'NotAllowed,Trinity,Allowed' string1 = 'NotAllowed,Allowe' name = frozenset(string1) if name.issubset(string) == 1: print 'yes' else: print 'no'
这将产生yes的输出。但是我想检查整个单词而不是一个字母一个字母。怎么可能?你知道吗
你必须把字符串转换成单词,然后你就可以用issubset来表示这个集合。你知道吗
issubset
string_words = string.split(',') string1_words = string1.split(',') if set(string1_words) <= set(string_words): print "yes" else: print "no"
您需要告诉它您的单词分隔符:
name = frozenset(string1.split(',')) if name.issubset(string.split(',')): print 'yes' else: print 'no'
你必须把字符串转换成单词,然后你就可以用
issubset
来表示这个集合。你知道吗您需要告诉它您的单词分隔符:
相关问题 更多 >
编程相关推荐