# Convert a list of lists into a list of rules

I have some trouble converting an imported list looking like this:

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


into a list of rules looking like this:

{{a -> b}, {c -> d}, {e -> f}}

• It is a list of lists of rules. But anyway: List@*Rule@@@... – Kuba Mar 1 '19 at 19:24
• Thx. So like this? data = {{a,b},{c,d},{e,f}} data@*Rule@@@ ? – user3483676 Mar 1 '19 at 19:35
• List@*Rule@@@data – Kuba Mar 1 '19 at 19:42
• Thx. It worked too. – user3483676 Mar 1 '19 at 19:44
• mathematica.stackexchange.com/q/88429 is a very similar question – m_goldberg Mar 2 '19 at 1:32

Why not

list = {{a, b}, {c, d}, {e, f}};
Rule @@@ list


{a -> b, c -> d, e -> f}

This will work as well as

{{a -> b}, {c -> d}, {e -> f}}


in just about every situation where you are likely need a list of rules.

Of course, if you must have the particular form that you show, there is

{#1 -> #2} & @@@ list


and

{#[] -> #[]} & /@ list


and

List @* Rule @@@ list


and

List @@@ Rule @@@ list


Why not:

list1 = {{a,b},{c,d},{e,f}};
list2 = Table[{list[[i, 1]] -> list[[i, 2]]}, {i, 1, Length[list]}]


prints out

{{a -> b}, {c -> d}, {e -> f}}

• Thx. It worked. – user3483676 Mar 1 '19 at 19:43