Counting and numbering duplicates in a list
Monte Goulding
monte at sweattechnologies.com
Wed Sep 28 23:23:29 EDT 2011
On 29/09/2011, at 12:52 PM, Roger Eller 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
Hmm... nice little challenge. How about:
put 1 into tIndex
repeat for each line tLine in tList
add 1 into tCounter[tLine]
switch tCounter[tLine]
case 1
put tLine into tOrder[tIndex]
put tIndex into tLocator[tLine]
break
case 2
-- go back and sequence the first instance
put tLine&"-"&1 into tOrder[tLocator[tLine]]
break
default
-- sequencing now
put tLine&"-"& tCounter[tLine] into tOrder[tIndex]
break
end switch
add 1 to tIndex
end repeat
repeat for each key tIndex in tOrder
put tOrder[tIndex]&cr after tResult
end repeat
More information about the use-livecode
mailing list