好的,这是 Python 2.7 和 Ren'Py 的一部分,所以请耐心等待(我生疏了,所以我可能只是在做一些非常愚蠢的事情)
我有一个输入:
input default "0" length 20 value VariableInputValue('playstore_search')
这将继续运行一个函数来检查(当前一个)嵌套列表中的匹配项:
if playstore_search.strip():
$ tempsearch = playstore_search.strip()
text tempsearch:
color "#000"
yalign .5 # this is just temporary to show me what the tempsearch looks like
$ realtimesearchresult = realtime_search(tempsearch,playstore_recommended)
if realtimesearchresult:
text "[realtimesearchresult]":
color "#000"
yalign .6
这继续调用这个函数:
def realtime_search(searchterm=False,listname=False):
if searchterm and listname:
indices = [i for i, s in enumerate(listname) if searchterm in s]
if indices:
return indices
而且,这是它搜索的修改后的列表:
default playstore_recommended = [
['HSS','Studio Errilhl','hss'],
['Making Movies','Droid Productions','makingmovies'],
['Life','Fasder','life'],
['xMassTransitx','xMTx','xmasstransitx'],
['Parental Love','Luxee','parentallove'],
['A Broken Family','KinneyX23','abrokenfamily'],
['Inevitable Relations','KinneyX23','inevitablerelations'],
['The DeLuca Family','HopesGaming','thedelucafamily'],
['A Cowboy\'s Story','Noller72','acowboysstory']
]
现在,如果我搜索hss
,它会找到那个 - 如果我搜索makingmovies
它会找到那个 - 但是,如果我搜索droid
(或Droid
因为它目前不区分大小写),它将找不到任何东西。
所以,这至少是一个双重问题:1.如何使整个事情不区分大小写 2.如何使其匹配部分字符串
编辑:
好的,所以东西现在有点工作了。但是,仍然存在一些问题。要匹配的完整列表比上面发布的要复杂得多,而且它似乎与“在字符串中间”的字符串命中不匹配 - 仅在第一个单词上。所以,如果我有这样的事情:
[
['This is a test string with the words game and move in it'],
['This is another test string, also containing game']
]
我搜索“游戏”,会得到两个结果。但是我得到 0。但是,如果我搜索“this”,我会得到两个结果。