Hi,
How is the best way to count the occurrences of values in a list? I have a
list with 6000+ random generated numbers and I need to count how many times
each of one appear.
Thank's in advance
Rodrigo Peres
[To remove yourself from this list, or to change to digest mode, go to
you could try to
1) sort the list from low to high
2) count the list (so you have the total number of items in the list)
3) the trick
x = getPos(mysortedlist,mysortedlist[nrofitemsinthelist]) -- this will
give you the FIRST occurence of the last item in the list
y = mysortedlist[x-1]) --gives
Well, you could do something like this (caution: untested e-mail Lingo)...
-- aList = #linearList or #propList
-- returns a #propList where
-- property is a value from aList
-- value is the number of occurrences of that aList value
on mListValuesCounts ( aList )
if not ilk ( aList, #list )
here some code that doesn't use any (lingo) repeat loop, so might be a
bit faster (but only works for lists that contain numbers only):
on howMany (tList, tValue)
tmp = tList.duplicate()
tmp.sort()
n = tmp.getPos(tValue)
if n = 0 then return 0
tmp = - tmp
tmp.sort()
return (tmp.count +
-- here's my take (similar to others)
-- it creates a proplist with
-- propnames = the occurance names
-- values = the counts
-- (email Lingo)
on cnt inList
testList = inList.duplicate()
testList.sort()
outPList = [:]
pCount = testList.count
repeat with i = 1 to pCount
pTarget =