[英]How do you search for strings within a string?
I'm writing a pig latin decoder.我正在写一个猪拉丁解码器。 This section works with 'qu' works but currently only is the third letter of the word is a vowel.
本节适用于“qu”作品,但目前只有单词的第三个字母是元音。 I am implementing an if statement to get it to work for words that have a consonant as the third letter, but keep getting this error: TypeError: 'in ' requires string as left operand, not list
我正在实现一个 if 语句,以使其适用于第三个字母为辅音的单词,但不断收到此错误: TypeError: 'in ' requires string as left operand, not list
Here is my code:这是我的代码:
if w[-2:] == 'ay':
RegW = []
y = w.find('-')
beginningw = w[y:]
if vowel not in beginningw[0]:
RegW.append(beginningw[0:-2] + w[0:y])
else:
RegW.append('qu' + w[0:y])
return RegW[0]
It works for these word: ay-quay (quay) iz-quay (quiz) eue-quay (queue)它适用于这些词:ay-quay (quay) iz-quay (quiz) eue-quay (queue)
but NOT an-quray (quran) (returns quan w/o if statement I'm trying to)但不是 an-quray (quran) (返回 quan w/o if 语句我正在尝试)
If vowel
is a list of vowel characters, I think you want this:如果
vowel
是元音字符的列表,我想你想要这个:
if beginningw[0] not in vowel:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.