• 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: getting duplicates in a list by item id
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting duplicates in a list by item id


  • Subject: Re: getting duplicates in a list by item id
  • From: Ed Stockly <email@hidden>
  • Date: Fri, 24 Aug 2007 21:08:43 -0700


So that I end up with two variables (one containing all paths only occuring 

once and the other containing all the line numbers. 

new POSIX path and then a list of  


Example

variable 1   variable 2 

PATH 1 --    1,3

PATH 2 --    2,5

-- path 3 was left out as it is now covered in the variable 2 - 1st line

PATH 4 --    4


Any ideas on how I do this sorting smartly? 

 

Don't know how "smartly" this is, but here's a pure appleScript solution that works.

I just might bog down with over 1000 paths. It could take several minutes.


HTH,

ES


set myList to "POSIX path 1 -- Joe - line 1 of file
POSIX path 2 -- Moe - line 2 of file
POSIX path 3 -- Joe - line 3 of file
POSIX path 4 -- John - line 4 of file
POSIX path 5 -- Moe - line 5 of file
POSIX path 6 -- Steve - line 6 of file
POSIX path 7 -- apple - line 7 of file
POSIX path 8 -- pie - line 8 of file
POSIX path 9 -- Janet - line 9 of file
POSIX path 10 -- Caroline - line 10 of file
POSIX path 11 -- apple - line 11 of file"

set text item delimiters to return
set myList to every text item of myList
set newList to {}
set pathInfo to {pathName:"", occourances:{}}
set occourancesList to {}
repeat with x from 1 to the count of myList
set text item delimiters to "-"
set thisPath to text item 3 of item x of myList
if thisPath is not in newList then
set the end of newList to thisPath
set the end of occourancesList to {thisPath, {x}}
else
repeat with y from 1 to the count of occourancesList
if item 1 of item y of occourancesList = thisPath then
set the end of item 2 of item y of occourancesList to x
end if
end repeat
end if
end repeat
repeat with x from 1 to the count of occourancesList
set AppleScript's text item delimiters to ", "
set item 2 of item x of occourancesList to item 2 of item x of occourancesList as string
set AppleScript's text item delimiters to ": "
set item x of occourancesList to item x of occourancesList as string
end repeat
set AppleScript's text item delimiters to return

return occourancesList as string

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

  • Prev by Date: Re: Reading and writing records
  • Next by Date: getting duplicates in a list by item id
  • Previous by thread: Re: getting duplicates in a list by item id
  • Next by thread: getting duplicates in a list by item id
  • Index(es):
    • Date
    • Thread