Re: Get position of item in list
Re: Get position of item in list
- Subject: Re: Get position of item in list
- From: Paul Skinner <email@hidden>
- Date: Wed, 25 Jun 2003 10:51:37 -0400
On Tuesday, June 24, 2003, at 08:46 PM, Kai wrote:
on Tue, 24 Jun 2003 11:46:15 -0400, Paul Skinner wrote:
But that cannot possibly be the most efficient algorithm.*
This one will (like Kai's) uses the TIDs to find the item. It also
returns ALL of the occurrences of the search term.
Snip
This (faster) alternative is an all-occurrence variation on my original
suggestion:
==============================
property d : ASCII character 1
to getPosition of i from l
if i is not in l then return 0
set {n, o, t, text item delimiters} to {0, {}, text item delimiters, d
& d}
set {l, text item delimiters} to {d & l & d, d & i & d}
set {l, text item delimiters} to {l's text items 1 thru -2, d & d}
repeat with i in l
set i to i as string
if i is not "" then set n to n + 1
tell n + (count i's text items) to set {n, o's end} to {it, it}
end repeat
set text item delimiters to t
o
end getPosition
set txtList to {"nine", "six", "six", "two", "sixteen", "sixty", "six"}
getPosition of "six" from txtList
--> {2, 3, 7}
==============================
--
Kai
Nice Kai, and with Richard Morton's modifications it's 77 percent
faster OMM.
ps
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.