search that value in list2
a. if list1 value is in list2 output the corresponding value
ex.
>list1: 1
>list2: 1 > 3434
>result is 3434
b. if list1 value is NOT in list2 output NOT found
Issues:
How can you find out what index is the value stored in without going through the entire list?
Anyone have code or can provide a direction that can do the above?
I know that someone will soon come up with a far more sophisticated solution, but until then code as follows might be sufficient
set listone to {1, 2, 3, 4, 5}
set listtwo to {{1, 444}, {3, 899}, {5, "t"}}
repeat with listoneval in listone
repeat with listtwoval in listtwo
set keyval to item 1 of listtwoval
if (keyval as integer) = (listoneval as integer) then
tell me
activate
display dialog "Found key " & listoneval & " in list two with value " & item 2 of listtwoval & "!"
end tell
end if
end repeat
end repeat
Unfortunately AppleScript doesn’t support real key-value dictionaries (like e.g. NSDictionary), so we must use nested lists instead.
set listone to {1, 2, 3, 4, 5}
set listtwo to {{1, 444}, {3, 899}, {5, "t"}}
repeat with x from 1 to count of listone
set p to FindinList(item x of listone, listtwo)
if p is false then display dialog (x & " Not Found") as string
end repeat
on FindinList(theitem, TheList)
set founditem to false
repeat with i from 1 to count of TheList
if item 1 of item i of TheList is theitem then set founditem to item 2 of item i of TheList
end repeat
return founditem
end FindinList