【发布时间】:2020-09-29 10:08:40
【问题描述】:
def can_spell_with(target_word, letter_word):
valid = True
target_word1 = [x.lower() for x in target_word]
letter_word1 = [x.lower() for x in letter_word]
for c in target_word1:
if c not in letter_word1:
valid = False
else:
valid = True
return valid
print(can_spell_with('elL','HEllo'))
# True
print(can_spell_with('ell','helo'))
# False
在上面的代码中:我试图弄清楚如果 letter_word 包含 target_word,如何返回 True。
所以 'helo' 中的 'ell' 会返回 False 但是 'hello' 中的 'ell' 会返回 True
【问题讨论】:
-
字符大小写是否重要,大写还是小写?
-
大小写无所谓,谢谢建议,里面的解释比较详细,谢谢
标签: python string for-loop duplicates lowercase