实际上,我在执行斯波吉的任务。如何检查字符串是否包含集合中的任何字符,但不能删除出现集合中字符的字符串中的第一个字符。你知道吗
F.e。 有一根绳子
word = "anAconda_elEphant"
以及一组元音:
vowels = set('aeiouyAEIOUY')
我想要一个字符串
word = "ancnd_lphnt"
当集合中任何字符的出现次数等于1时,该值应返回True。我知道方法.count()的参数必须是str,而不是set。你知道吗
if word.count(vowels) == 1:
for char in word[char_pos:]:
if char in vowels:
char.replace('')
只需使用正则表达式
如前所述,如果您希望它跳过集合的第一个匹配,而不是仅仅跳过第一个字母,您将需要一个不同的解决方案
最简单的方法是把它分成两个步骤 在第一场比赛中先把绳子分开
https://docs.python.org/3/library/stdtypes.html#frozenset.intersection
您可以使用
for
循环,如下所示。其思想是构建一个列表,并在遇到来自vowels
的字符时使用标志进行标记。你知道吗相关问题 更多 >
编程相关推荐