Equating two lists, element by element

Say you have two lists:

listA = {a, b, c}

listB = {d, e, f}

How would you produce a listC that equates each of the two's elements, ie.

listC = {a == d, b == e, c == f} ?

I know, it's very easy, but somehow I've already spent an slightly embarrassing amount of time on this. I suspect it will involve Map, but can't seem to get the elements to behave together per each element. It seems to just Append the two together for some reason.

SetAttributes[listA, Listable] SetAttributes[listB, Listable]

seems promising given this: http://reference.wolfram.com/mathematica/ref/Listable.html

• Thread[listA == listB] – rm -rf Jun 12 '13 at 0:45
• @rm -rf thank you – Ghersic Jun 12 '13 at 0:47
• @rm-rf If listA is equal to listB, then Thread[listA == listB] will return just True. In that case, this: MapThread[Equal, {listA, listB}]. – Michael E2 Jun 12 '13 at 5:37
• – István Zachar Jun 12 '13 at 7:43
• Also related: (10211) (15556) – Mr.Wizard Jan 18 '15 at 15:29

As @rm -rf mentioned in the comments,

Thread[listA == listB]

accomplishes what I'd hoped. Apoogies for missing this.

As Michael notes, if they are already equal to these values (you're not newly naming listA or listB) and they happen to already be equal , the query just returns "true." If this is the case, use:

MapThread[Equal, {listA, listB}]

as mentioned by MichaelE2 in the comments.

• MapThread gives True/False. Any quick way to get them to 1 and 0? – Chen Stats Yu Nov 26 '17 at 21:41
• @ChenStatsYu If I understand, you would like "True" to be indicated with a 1 and "False" with a 0? MapThread[Equal, {list1, list2}] /. {True :> 1, False :> 0} achieves this result. If it is something other than True/False, a conditional statement such as MapThread[~] /. {x_ /; x != True :> 0} should work, but doesn't - I think due to the unequal operator. However, some such conditional statement dependent upon the entity being replaced should suffice, or you can use Cases[~] or Position[MapThreads[~], True] to eliminate or detect, respectively, which statements were True. – Ghersic Dec 5 '17 at 17:12
• @ChenStatsYu Boole does this – b3m2a1 Nov 17 '19 at 22:16

Also

Inner[Equal, listA, listB, List]
Equal @@@ Transpose[{listA, listB}]


{a == d, b == e, c == f}

• How about setting variable list to equal values list variables = {"a", "b", "c", "d", "e"}, list = {0.745581, -0.412515, 0.701289, 0.666934, -0.559174}, list3 = Thread[variables = list], then IN a give OUT a ? – SPIL Nov 14 '17 at 10:33
• Years late "thanks," kglr. I did +1 back in 2013! SPIL, I'm not exactly sure what you're asking, but if you've a reasonably short list the notebook Frontend can display it all, skipping preliminary list definitions entirely and saying {a, b, c} = {1, 2, 3} will auto-thread Set over each pair. How to do this for sufficiently large lists that they must be represented internally is another question; it is probably doable via Part and Table or maybe Map. If setting a bunch of variables to a bunch of values is what you're after anyways... You will want to remove the quotes though. – Ghersic Dec 5 '17 at 18:48