Atiye Sadeghy
Atiye Sadeghy

Reputation: 11

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

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?

Upvotes: 1

Views: 217

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

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]

Upvotes: 3

Related Questions