如何查找序列字符串是否包含在PYTHON中设置的所有项目

问题描述 投票:-1回答:1

我生成8个随机字符:“ ghdteoba”

用户输入:“蝙蝠”

返回true,因为“ bat”包含在'ghdteoba'中>]

如果用户输入:boot

返回false,因为'boot'不包含在'ghdteoba'中(需要再输入一个O)

如何在python中解决这个问题。另外,请使用搜索算法。

我生成8个随机字符:“ ghdteoba”用户输入:“ bat”返回true,因为如果用户输入:boot,则“ bat”包含在“ ghdteoba”中,因为“ boot”不是...,所以返回false]]

python algorithm sorting binary-search-tree
1个回答
0
投票
也许类似的东西会帮助您:

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)

© www.soinside.com 2019 - 2024. All rights reserved.