Counting and numbering duplicates in a list

Pete pete at mollysrevenge.com
Thu Sep 29 02:46:02 EDT 2011


Where are this list of keys coming from?  If from an SQL database, this
could be done with an SQL SELECT statement with no need to write LC code.
 Don't know if it would be faster than LC without more information.
Pete
Molly's Revenge <http://www.mollysrevenge.com>




On Wed, Sep 28, 2011 at 11:28 PM, Dick Kriesel <dick.kriesel at mail.com>wrote:

> 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
> _______________________________________________
> 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
>
>



More information about the Use-livecode mailing list