在嵌套列表中查找索引
可能的重复:
Python 中的高效单词索引
对基本问题表示歉意,如何找到索引< code>((1,2),(2,1),(2,2)) 对应于 ref
中的“yellow”并存储它们,以便我可以在事后访问它们而无需重新运行搜索?
ref1 = "this is a test"
ref2 = "this is a yellow test"
ref3 = "this is yellow"
ref4 = "yellow and orange are colors"
ref = ((ref1,ref2),(ref3,ref4))
Possible Duplicate:
efficient word indexing in python
Apologies for the basic question, how can I find the indexes ((1,2),(2,1),(2,2))
corresponding to "yellow" in ref
and store them so that I can access them afterwords without rerunning the search?
ref1 = "this is a test"
ref2 = "this is a yellow test"
ref3 = "this is yellow"
ref4 = "yellow and orange are colors"
ref = ((ref1,ref2),(ref3,ref4))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了它:
但您可能想要真正的索引(从零开始)...如果是这样,请删除
enumerate
的第二个参数。Just for the sake of it:
but you probably want the real index (starting at zero)... Remove the second argument of
enumerate
if so.我不确定你的意思,但是如果你想在每次看到“黄色”这个词时从嵌套列表(或元组)的列表(或元组)中生成一个对的列表,那么:
I'm not sure what you mean, but if you want to generate a list of pairs from a list (or tuple) of nested lists (or tuples) for every time you see the word 'yellow' then: