# List comparison questions

I came across this issue last week, and am hoping someone can offer an explanation or some guidance.

Given a long list of 2 numbers, I need to find any matching instances, but this will not work:

``````set a to {{1, 2}, {2, 3}, {3, 4}}
set b to {2, 3}
a contains b
-->false
``````

Neither will this:

``````set a to {{1, 2}, {2, 3}, {3, 4}}
set b to {2, 3}
set the_count to 0
repeat with c in a
if c is equal to b then
set the_count to the_count + 1
end if
end repeat
the_count
-->0

``````

But, if you test a single item of a list to see if it contains another list, it works:

``````set a to {{1, 2}, {2, 3}, {3, 4}}
set b to {2, 3}
set the_count to 0
repeat with c in a
if c contains b then
set the_count to the_count + 1
end if
end repeat
the_count
-->1
``````

Is there some kind of rule that needs to be remembered when trying to find out whether or not a list is already present in another list?

Your second one works with this change:

``````set a to {{1, 2}, {2, 3}, {1, 2}}
set b to {1, 2}
set the_count to 0
repeat with c in a
if contents of c is equal to contents of b then
set the_count to the_count + 1
end if
end repeat
the_count
--> 2

``````

With several variations, I cannot get the first to work, but cannot explain why.

Hi,

Here’s an article:

http://www.applescriptsourcebook.com/tips/gotchas/listoflists.html

Basically, AppleScript requires list of lists on both sides of the ‘contained by’ operator.

set a to {{1, 2}, {2, 3}, {3, 4}}
set b to {{2, 3}}
a contains b

gl,

kel:

Thanks loads; good article! That speeded things up nicely.