Re: Find index of list to find item in another list
Re: Find index of list to find item in another list
- Subject: Re: Find index of list to find item in another list
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 1 Jul 2009 12:39:13 -0400
See thread here: http://forums.macosxhints.com/archive/index.php/t-89313.html
Short answer: no, you can't find the index of a desired item in a list
without looping through the list.
On Wed, Jul 1, 2009 at 11:09 AM, Jim Skibbie<email@hidden> wrote:
> I have a task where I need to compare one list of values with another. The
> lists are quite large, so I’m wondering if there’s any way to not have to
> loop over the entire list to find the values. For example, I have data that
> is separated into jobs and related items, so:
>
> 123456 has items A, B, C
> 123457 has item D
> 123458 has items E, F
>
> I can create this as separate lists like:
>
> --the really big lists
> set X to {"123456", "123457", "123458"}
> set Y to {{"A", "B", "C"}, {"D"}, {"E", "F"}}
>
> -- the item I'm looking for
> set Z to "123457"
>
> I need to know several things about the relationship of “Z” to “X” and “Y”.
> The first is whether X contains Z. That part seems easy.
>
> X contains Z --> true
>
> But what I really need to know is the index of where in X the value of Z was
> found (in the example it was the second item) so that I can pick up it’s
> related information from Y:
>
> item 2 of Y --> {“D”}
>
> Short of iterating through the whole list one at a time, is there a
> low-level way to get the index number of X where Z is located?
>
> Is there a way to do this more easily with a record instead of a list as I
> could form the variables for X and Y any way I want?
>
> Thanks.
> Jim
> _______________________________________________
> 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
>
--
Mark J. Reed <email@hidden>
_______________________________________________
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