NetLogo : How to do multiple operations on lists (find, get , replace, remove , search elements within lists , ....)
By : Joel
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further map, filter, reduce, foreach, n-values, and sort-by provide customizable operations on lists, using tasks. See http://ccl.northwestern.edu/netlogo/docs/programming.html#tasks. Here's your example using map: code :
observer> show member? 3 map first [[1 2] [2 2] [2 3]]
observer: false
observer> show member? 3 map last [[1 2] [2 2] [2 3]]
observer: true
|
Groovy compare two lists to find lists with common elements
By : Bruno Marques
Date : March 29 2020, 07:55 AM
I hope this helps you . How do I compare two lists in groovy , I solved by code :
List newList = ["ABCD9", "ABCD8", "ABCD7"]
List oldList = ["dfgdfg"]
if(newList.intersect(oldList))
println("difference->")
|
Find smaller subset when comparing elements in two lists of lists
By : Civelek
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Since you are treating those lists of lists rather as sets, with order seemingly not being important and regarding subsets and the like, it might help to actually convert those to sets of sets (or actually, set of frozenset). Then, you can use set operations like &, ^, < or - to find the result. code :
>>> a = [1],[2,3,4],[5,6],[7,8,9],[10,11,12,13]
>>> b = [1,2,3,4],[5,6],[7,8,9],[10,11,12],[13]
>>> aset = set(map(frozenset, a))
>>> bset = set(map(frozenset, b))
>>> aset & bset
{frozenset({5, 6}), frozenset({7, 8, 9})}
>>> [min(sub, key=len) for sub in ([y for y in aset if y < x] for x in bset - aset) if sub]
[frozenset({1})]
>>> [min(sub, key=len) for sub in ([y for y in bset if y < x] for x in aset - bset) if sub]
[frozenset({13})]
>>> [(x, min((y for y in bset if y < x), key=len, default=None)) for x in aset - bset]
[(frozenset({10, 11, 12, 13}), frozenset({13})),
(frozenset({2, 3, 4}), None),
(frozenset({1}), None)]
|
Compare two lists to find the new elements, the removed elements and the existing elements
By : Jee Franger
Date : March 29 2020, 07:55 AM
To fix this issue I would build your array operations atop set ones. Since there are not supposed to be duplicates, this is the correct structure for internal calculations. I don't know why Set.prototype does not have on it at least union, intersection, and difference, but it's quite trivial to write them yourself. code :
// Set operations
const intersection = (set1, set2) => new Set([...set1].filter(x => set2.has(x)))
const difference = (set1, set2) => new Set([...set1].filter(x => !set2.has(x)))
// Array operations, builtt using the set ones
// NB: Arrays are NOT Sets, and there is some information lost in the conversion.
// But Sets are the proper data structure for unordered collections of unique values.
const intersectionA = (arr1, arr2) => Array.from(intersection(new Set(arr1), new Set(arr2)))
const differenceA = (arr1, arr2) => Array.from(difference(new Set(arr1), new Set(arr2)))
// Main code
const breakdown = (prev, curr) => ({
delete_id: differenceA(prev, curr),
new_id: differenceA(curr, prev),
existing_id: intersectionA(prev, curr)
})
let previous_id = ["5b7b5498ab3f510e307e7d04", "5b7ae97cc6d75e1331e28d9c", "5b7a0c207fab2722a2081caf"];
let current_id = ["5b7b5498ab3f510e307e7d04", "5b83e3b4412f370bd7b9a05d"];
console.log(breakdown(previous_id, current_id))
|
Find the same elements from two lists and print the elements from both lists
By : Nedyalka Bradova
Date : March 29 2020, 07:55 AM
I wish this help you There are two lists:
|