Counting and numbering duplicates in a list

Ian McKnight iangmcknight at gmail.com
Wed Sep 28 23:25:23 EDT 2011


Hi Roger

My first thought would be to set up an array having your numbers as keys.
Cycle through each key counting the occurrence of each number in your master
list and then separate out the key values that are greater than one. Use the
offset function to reference each value in the master list - the subsequent
values could be accessed by using the 'skip' parameter in the offset
function.

Something like this (untested)

--create an array and count
repeat for each line myNumber in myNumberList
add 1 to myNumberListArray[myNumber]
end repeat

put the keys of myNumberListArray into myKeys
sort myKeys ascending

repeat for each line myNumber in myKeys

-- identify multiple values
if myNumberListArray[myNumber] > 1
then

put empty into linesToSkip
repeat with tCount = 1 to myNumberListArray[myNumber]

put lineoffset(myNumber, myNumberList, linesToSkip) into tValuePosition
put "-"&tCount after line tValuePositionof myNumberList
put tValuePosition into linesToSkip

end if

end repeat


HTH


On 29 September 2011 03:52, Roger Eller <roger.e.eller at sealedair.com> wrote:

> There are several ways I could approach this, but I'm unsure which way is
> best?  I have a list of numbers that 'may' contain duplicates.  I need to
> sequence ONLY the duplicates without changing the order the list. If there
> is only one, it does not need to be sequenced.
>
> Should I just repeat, and keep the content of line x in a variable, then
> add
> 1 to a sequence variable if the number is encountered again?  Is there a
> better way?  Simple stuff, I know, but these lists can be really long, and
> I
> want it to process as quickly possible.
>
> 12345
> 12345
> 12344
> 12333
> 10112
> 12333
>
> must become:
>
> 12345-1
> 12345-2
> 12344
> 12333-1
> 10112
> 12333-2
>
> ˜Roger
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



-- 
Regards


Ian McKnight

iangmcknight at gmail.com
=======================



More information about the use-livecode mailing list