针对方案中的列表列表运行查询
我被困在我的项目中。我有一个列表列表,例如:
'((a for apple) (b is book) (c in cat) (ronn live in NY))
现在我想以列表的形式进行查询,并让它在我的列表列表中显示正确的条目。例如,如果我输入 '(a for what)
或 '(what in cat)
它将显示 (a for apple)
或 <代码>(猫中的c)。如果我输入'(ronn live in where)
,它将显示(ronn live in NY)
。
谁能帮我解决这个问题吗?
I'm stuck in the middle of my project. I have a list of lists like:
'((a for apple) (b is book) (c in cat) (ronn live in NY))
Now I want to make a query in the form of a list and have it display the correct entry in my list of lists. For example, if I input '(a for what)
or '(what in cat)
it will display (a for apple)
or (c in cat)
. If I input '(ronn live in where)
it will show (ronn live in NY)
.
Can anyone help me solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何在列表中运行
filter
例程,并使用用查询信息初始化的 lambda 对象,然后将其应用于列表,直到找到匹配项。例如,您将有一个看起来像这样的 lamda
现在,在初始化了
filter-object
的情况下,在您的列表中运行一个过滤器这应该返回一个匹配的单元素列表(假设您是不要在您的列表集中放置多个副本,
希望这会有所帮助,
杰森。
How about running a
filter
routine across the list, and using a lambda object initialized with your query information that will then be applied to the list until it finds a match.So for instance, you would have a lamda that would look something like
Now with the
filter-object
initialized, run a filter across your listThis should return a one-element list of the matches (providing you aren't placing more than one copy in your list set.
Hope this helps,
Jason
计算机程序的结构和解释,Hal Abelson 和 Gerald 的视频讲座Jay Sussman
讲座 4a,模式匹配和基于规则的替换
Structure and Interpretation of Computer Programs, Video Lectures by Hal Abelson and Gerald Jay Sussman
Lecture 4a, Pattern Matching and Rule-based Substitution