我生成8个随机字符:“ ghdteoba”
用户输入:“蝙蝠”
返回true,因为“ bat”包含在'ghdteoba'中>]
如果用户输入:boot
返回false,因为'boot'不包含在'ghdteoba'中(需要再输入一个O)
如何在python中解决这个问题。另外,请使用搜索算法。
我生成8个随机字符:“ ghdteoba”用户输入:“ bat”返回true,因为如果用户输入:boot,则“ bat”包含在“ ghdteoba”中,因为“ boot”不是...,所以返回false]]
data = 'ghdteoba'
sample = 'boot'
response = True
for letter in sample:
len_letter_in_sample = sample.count(letter)
len_letter_in_data = data.count(letter)
if len_letter_in_data < len_letter_in_sample:
response = False
break
print(response)