获得列表Elemnt的特定部分

发布于 2025-02-06 13:37:17 字数 151 浏览 2 评论 0原文

我有此列表[c1 = 2*3,c2 = 5*1,c3 = 1*1],我想创建一个新列表,只有列表的每个元素的第三元素,因此,像这样的东西[2,5,1]。我正在使用NTH0访问列表的每个元素,但是从那里我无法进一步进步。先感谢您。

I have this list [c1=2*3,c2=5*1,c3=1*1] and i want to create a new list with just the 3rd element of each element of the list, so something like this [2,5,1]. I'm using nth0 to access each of the elements of the list but from there i can't progress much further. Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2025-02-13 13:37:17

从您的示例中,我假设列表由表单(a = b * c)的元素组成他们。在这种情况下,可能的解决方案如下:

filter([], []).
filter([(_ = B * _)|Xs], [B|Ys]) :- filter(Xs, Ys).

示例:

?- filter([c1=2*3, c2=5*1, c3=1*1], L).
L = [2, 5, 1].

From your example, I assume that the list is composed by elements of the form (A = B * C) and that you want to filter only the component B of each one of them. In this case, a possible solution is as follows:

filter([], []).
filter([(_ = B * _)|Xs], [B|Ys]) :- filter(Xs, Ys).

Example:

?- filter([c1=2*3, c2=5*1, c3=1*1], L).
L = [2, 5, 1].
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文