List difference (omit one list from other list) in NetLogo

十年热恋 提交于 2019-12-11 10:37:57

问题


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?


回答1:


Code:

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

Sample runs:

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]


来源:https://stackoverflow.com/questions/30895592/list-difference-omit-one-list-from-other-list-in-netlogo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!