Python 用户输入的输入必须返回列表中的所有索引,并在其名称中包含该输入
例如,如果我输入:Python 用户输入的输入必须返回列表中的所有索引,并在其名称中包含该输入,python,list,Python,List,例如,如果我输入:“the” 我需要能够检测列表中包含“”的所有标题 my_list = ["The offspring", "legends", "the legends", "soraka"] 根据上面的列表,它应该返回“后代”和“图例”。 如果我写全名,我可以检测标题,但是当我被要求输入标题的一部分时,我遇到了问题,例如,“the”,此时我不确定使用哪种函数或循环 lst = ['the offspring','legends','the legends','soraka'] for
“the”
我需要能够检测列表中包含“”的所有标题
my_list = ["The offspring", "legends", "the legends", "soraka"]
根据上面的列表,它应该返回“后代”
和“图例”
。
如果我写全名,我可以检测标题,但是当我被要求输入标题的一部分时,我遇到了问题,例如,“the”
,此时我不确定使用哪种函数或循环
lst = ['the offspring','legends','the legends','soraka']
for i in lst:
if 'the' in i:
print(i)
这是我将如何检查名单内,希望这有帮助 这一行可以帮你处理
filter(lambda x: "the" in x.lower().split(), ["The foo", "bar The", "baz"])
拆分的原因是只匹配整个单词