Counting and numbering duplicates in a list
Dick Kriesel
dick.kriesel at mail.com
Thu Sep 29 02:28:47 EDT 2011
On Sep 28, 2011, at 9:55 PM, Jan Schenkel wrote:
> command Dupend @pInput, @pOutput
> local tLineDA, tLine
> repeat for each line tLine in pInput
> add 1 to tLineDA[tLine]["found"]
> end repeat
> put empty into pOutput
> repeat for each line tLine in pInput
> if tLineDA[tLine]["found"] = 1 then
> put tLine & return after pOutput
> else
> add 1 to tLineDA[tLine]["current"]
> put tLine & "-" & tLineDA[tLine]["current"] & return after pOutput
> end if
> end repeat
> delete char -1 of pOutput
> end Dupend##
Shallower arrays might help a little.
<script>
function numberDuplicates pList
local tCount, tIndex, tList
repeat for each line tLine in pList
add 1 to tCount[ tLine ]
end repeat
repeat for each line tLine in pList
if tCount[ tLine ] = 1 then
put tLine & cr after tList
else
add 1 to tIndex[ tLine ]
put tLine & "-" & tIndex[ tLine ] & cr after tList
end if
end repeat
return tList
end numberDuplicates
</script>
Roger, will you share your timings for the various suggestions to crunch your big list?
-- Dick
More information about the use-livecode
mailing list