Re: What is Best Method To Determine Duplicate Items in a Large List?
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