# Create a bijection between two lists

Is there a way to create a two-way association or a bijection between two lists of equal length? I know I can use AssociationThread twice, flipping the arguments, but how can I create a bijective function which associates each element in one list with an element of another, and vice-versa?

• In what way does the solution you mention fall short of what you want?
– Alan
Sep 13, 2016 at 3:21
• @Alan its more clunky: using two variables instead of one. Sep 13, 2016 at 3:24

A bijective function:

list1 = {1, 2, 3, 4};
list2 = {5, 6, 7, 8};
MapThread[(f[#] = #2; f[#2] = #) &, {list1, list2}]

f[2]
(* Out: 6 *)


And the AssociationThread solution that you mention:

f = <|AssociationThread[list1 -> list2], AssociationThread[list2 -> list1]|>;

f[2]
(* Out: 6 *)