所以我对 Netlogo 中的列表有点挣扎,所以基本上我有两个列表,我想从列表 2 中删除列表 1 中的项目,例如:
列表 1:[8 6 9 7 1 3]
列表2:[5 9 8]
结果列表:[6 7 1 3]
我已尝试以下代码,但它返回一个空列表:
if List 2 != []
[
foreach List 2
[
let p position ? List 1
if p = true
[
set List 1 remove-item p List 1
]
]
]
有任何想法吗 ?
的组合member? http://ccl.northwestern.edu/netlogo/docs/dictionary.html#member and filter http://ccl.northwestern.edu/netlogo/docs/dictionary.html#filter会带你去那里:
let list1 [8 6 9 7 1 3]
let list2 [5 9 8]
let result filter [ x -> not member? x list2 ] list1
print result
将打印所需的:
[6 7 1 3]
提示:每当您发现自己尝试对 NetLogo 中的任何内容使用索引时,您可能没有以最佳方式做事。 NetLogo 有大量的功能(例如filter
,在本例中)对整个列表进行操作。很少需要显式地循环它们。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)