NetLogo中的列表差异(从其他列表中省略一个列表) [英] List difference (omit one list from other list) in NetLogo

查看:90
本文介绍了NetLogo中的列表差异(从其他列表中省略一个列表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们要在Netlogo中的其他列表中省略一个列表,我们应该如何编写代码? 例如,第一个列表是[1 2 3 4 5] 第二个列表是[4 5] 在这种情况下,应该编写什么代码从列表1中删除列表2,以使新列表包含1、2和3?

In case we want to omit one list from other list in Netlogo , how we should write the code? For example, first list is [1 2 3 4 5] And second list is [4 5] In this case what code should be written to remove list 2 from list 1 so as to having a new list comprises of 1, 2 and 3?

推荐答案

代码:

to-report difference [l1 l2]
  report filter [not member? ? l2] l1
end

示例运行:

observer> show difference [1 2 3 4 5] [4 5]
observer: [1 2 3]
observer> show difference [1 2 3 6] [1 2 3 4 5]
observer: [6]

这篇关于NetLogo中的列表差异(从其他列表中省略一个列表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆