好吧,这是Python2.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”,我会得到两个结果。你知道吗
我建议先将嵌套列表中的条目转换为小写,然后使用
find()
搜索术语。考虑以下功能:使用上述代码,
result
的值为:如果希望从整个列表列表中仅查找一个布尔值,请执行以下操作:
如果您使用
searchFor = 'droid'
,它也应该返回True
。你知道吗为了找到
True
的索引,我建议使用来自numpy
的where
命令例如,
searchFor = 'life'
,idx
的值将是:要查找索引而不使用
numpy
(没有那么优雅):这将给出与发生匹配的索引对应的正值,否则将给出
-1
。你知道吗希望有帮助!你知道吗
相关问题 更多 >
编程相关推荐