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: Tue, 15 Aug 2017 10:36:48 +1000
On 15 Aug 2017, at 1:07 am, Jim Underwood <email@hidden> wrote:
>
> That worked, after I identified the correct line to change.
Sorry -- I pasted the wrong line in there.
> So, how do we sort IndexInfo on item 2?
The simplest way would be to change the order so it's first or last -- then
your sort key would firstItem or lastItem. There's no direct way to sort based
on index (other than BridgePlus's
subarraysIn:sortedByIndexes:ascending:sortTypes:error:).
You could also store the results as a list of records instead of lists
({{theItem:"blah blah", firstIndex:23, dupeIndexes:{56, 89}}, ...}. So change
the last part to this:
set indexInfo to current application's NSMutableArray's array()
repeat with thisValue in duplicatedValues
-- Value and first index.
set thisIndex to (theBigList's indexOfObject:(thisValue)) + 1
copy thisIndex to theFirstIndex
set dupeIndexes to {}
-- Indices of dupes.
repeat (countedDupes's countForObject:(thisValue)) times
set thisIndex to (theBigList's indexOfObject:(thisValue)
inRange:({thisIndex, theCount - thisIndex})) + 1
set end of dupeIndexes to thisIndex
end repeat
(indexInfo's addObject:(current application's NSDictionary's
dictionaryWithObjects:{thisValue, theFirstIndex, dupeIndexes}
forKeys:{"theValue", "firstIndex", "dupeIndexes"}))
end repeat
indexInfo's sortUsingDescriptors:{current application's NSSortDescriptor's
sortDescriptorWithKey:"firstIndex" ascending:true}
set indexInfo to indexInfo as list
--
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