• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: What is Best Method To Determine Duplicate Items in a Large List?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is Best Method To Determine Duplicate Items in a Large List?


  • Subject: Re: What is Best Method To Determine Duplicate Items in a Large List?
  • From: Shane Stanley <email@hidden>
  • Date: Sun, 13 Aug 2017 14:06:34 +1000

On 13 Aug 2017, at 1:09 pm, Jim Underwood <email@hidden> wrote:
>
> I need to identify the index numbers of the dup items,

There might be a quicker way, but this should do the trick:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theBigList to {"a", "b", "c", "d", "e", "f", "g", "h", "a", "i", "e", "e"}
set theBigList to current application's NSArray's arrayWithArray:theBigList
set theCount to theBigList's |count|()
-- get duplicate items
set theCountedSet to current application's NSCountedSet's
setWithArray:theBigList
theCountedSet's minusSet:(current application's NSSet's
setWithSet:theCountedSet)
set theDupes to theCountedSet's allObjects()
-- get index of the dupes
set indexInfo to {} -- to hold info
set theStart to 0
repeat with aDupe in theDupes
        set end of indexInfo to {aDupe as text}
        repeat
                set theIndex to (theBigList's indexOfObject:aDupe
inRange:{theStart, theCount - theStart})
                if theIndex > theCount - 1 then -- not found, so move to next
dupe
                        set theStart to 0
                        exit repeat
                else if theIndex = theCount - 1 then -- last item, so record
and move to next dupe
                        set end of item -1 of indexInfo to theIndex + 1
                        set theStart to 0
                        exit repeat
                else -- record and update start range
                        set end of item -1 of indexInfo to theIndex + 1
                        set theStart to theIndex + 1
                end if
        end repeat
end repeat
return indexInfo
--> {{"e", 5, 11, 12}, {"a", 1, 9}}

--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >What is Best Method To Determine Duplicate Items in a Large List? (From: Jim Underwood <email@hidden>)
 >Re: What is Best Method To Determine Duplicate Items in a Large List? (From: Hans van den Broek <email@hidden>)
 >Re: What is Best Method To Determine Duplicate Items in a Large List? (From: Jim Underwood <email@hidden>)

  • Prev by Date: Re: What is Best Method To Determine Duplicate Items in a Large List?
  • Next by Date: Re: What is Best Method To Determine Duplicate Items in a Large List?
  • Previous by thread: Re: What is Best Method To Determine Duplicate Items in a Large List?
  • Next by thread: Re: What is Best Method To Determine Duplicate Items in a Large List?
  • Index(es):
    • Date
    • Thread