匹配和删除元组列表中的项目
我有一个元组列表,比如说,
[{x, a, y}, {x, b, y}].
是否有一个内置函数(或者我可以使用 BIF 的组合)来删除所有匹配 {x, _, y}
的元组,如 match 和根据元组中的第一项和第三项删除,忽略第二项?
I have a list of tuples, say,
[{x, a, y}, {x, b, y}].
Is there a built-in function (or can I use a combination of BIFs) to delete all tuples matching {x, _, y}
, as in match and delete based on the first and third term in the tuples, ignoring the second?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
lists:filter/1 函数符合您的需求,例如
您还可以使用列表推导式,就像lists:map/2 和lists:filter/2 的组合。
如果你的谓词是相反的,因为你只想要那些匹配的 {x,_,y} 你可以写如下,因为生成器会过滤掉那些不匹配模式的。
The lists:filter/1 function matches your need, e.g.
You can also use list comprehensions, which is like a combination of lists:map/2 and lists:filter/2.
If your predicate was the opposite, in that you only wanted those matching {x,_,y} you could write it as following, because the generator will filter out those not matching the pattern.