# Reverse element in nested list

Suppose I have a list as the following:

list={{1,9},{7,0},{8,6}....}


How can I reverse the element in such way that the output would be the following:

{{9,1},{0,7},{6,8}....}


I tried Map[Reverse,{list}] but it didn't work.

• Either list[[All, {2,1}]], or more generally list[[All, Reverse[Range[Length[First[list]]]]]] Commented Feb 3, 2016 at 20:12
• Take away the {}'s: Map[Reverse, list] or Reverse /@ map. Commented Feb 3, 2016 at 20:38
• Closely related Why is multidimensional Reverse slow?
– Kuba
Commented Feb 3, 2016 at 20:45

Reverse takes a level specification so:

Reverse[list, 2]


Another approach would be to use a simple pattern match and replacement rule, such as:

list = {{1, 9}, {7, 0}, {8, 6}};
list /. {a_?NumberQ, b_?NumberQ} :> {b, a}
(*  {{9, 1}, {0, 7}, {6, 8}}. *)


For this specific example, you could drop the ?NumberQs from the pattern to be matched. But, without them, the approach would not produce the intended outcome if the length of the outer list were 2. For that case, the outcome would be as follows:

{{1, 9}, {7, 0}} /. {a_, b_} :> {b, a}
(*. {{7, 0}, {1, 9}}. *)