Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用户输入的输入必须返回列表中的所有索引,并在其名称中包含该输入_Python_List - Fatal编程技术网

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"])
拆分的原因是只匹配整个单词