题解 | #字符串字符匹配#
字符串字符匹配
https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93
import sys def all_chars_in_text(pattern,text): pattern_set = set(pattern) text_set = set(text) return pattern_set.issubset(text_set) List = [] for line in sys.stdin: if line.strip() == "": break else: X = line.strip() List.append(X) pattern = List[0] text = List[1] if all_chars_in_text(pattern,text): print('true') else: print('false')
利用issubset方法,判断模式串set是否为文本串set的子集