# How to make a table from two lists?

I have two lists.

list1 = {115.366, 103.583, 115.24, 91.4648, 93.1291, 485.744, 427.888,489.401, 403.942}

list2 = {114.062, 105.17, 114.857, 91.6497, 93.2112, 398.588, 458.713,410.015, 380.659}


I want these lists to form a table that looks like this.

115.366    114.062
103.583    105.17
115.24     114.857
and so on


Transpose[{list1, list2}] // TableForm


$\begin{array}{cc} 115.366 & 114.062 \\ 103.583 & 105.17 \\ 115.24 & 114.857 \\ 91.4648 & 91.6497 \\ 93.1291 & 93.2112 \\ 485.744 & 398.588 \\ 427.888 & 458.713 \\ 489.401 & 410.015 \\ 403.942 & 380.659 \\ \end{array}$

And then there is Grid:

transposedData = Transpose @ { list1, list2 }; (* make a list of tuples *)

Grid[
transposedData,
(* options for further formatting go here *)
]


Just to give an idea of what is possible using options for Grid:

Grid[
transposedData,
Frame -> {All, None, {{3, 2} -> Directive[Red, Thick]}},
Alignment -> {Decimal, Decimal}
]


Although solution has been already accepted, here is another way it could be done

## Example

Code

Row[(Column[#, Frame -> True] & /@ {list1, list2})]


Note: list1 and list2 as in OP

Output

Reference

Thanks to the @cvgmt's feedback, alternatives to Transpose:

## Code 1

Thread[{list1, list2}]

% == Transpose[{list1, list2}]
(* Out: True *)


## Code 2

Can only be used on two lists, each of them should be 1-dimensional:

Inner[List, list1, list2, List]

% == Transpose[{list1, list2}]
(* Out: True *)


## Speed Comparison

lg[n_] := ConstantArray[RandomReal[{-1, 1}, 10^n], 2]

inner[{l1_, l2_}] := Inner[List, l1, l2, List];
transpose[{l1_, l2_}] := Transpose[{l1, l2}];

Needs["GeneralUtilities"]
BenchmarkPlot[{thread, inner, transpose}, lg, TimeConstrained -> 20]


Result:

• Transpose is faster then others. list1 = RandomReal[{-1, 1}, 10^6]; list2 = RandomReal[{-1, 1}, 10^6]; Thread[List[list1, list2]]; // AbsoluteTiming Inner[List, list1, list2, List]; // AbsoluteTiming Transpose[List[list1, list2]]; // AbsoluteTiming Mar 25, 2021 at 9:04

A new approach is based on the command ArrayReduce and it works in the following manner:

TableForm@ArrayReduce[Dot, {list1, list2}, 1]


Another alternative is based on the use of Multicolumn. It works like this:

Multicolumn[Flatten@ArrayReshape[{list1, list2}, {2, Length@list1}],
2]


In the above command, we can add at the end [[1]] // TableForm optionally. This will create a List and bring it into TableForm.

The output of the two commands above is

• @user1066 very good points. Thanks for pointing those out. Indeed, ArrayReduce seems a very nice and useful gadget to have and I definitely need more practice with it :-)
– bmf
Feb 1 at 1:27

In[1]= myThread[l1__, l2__] := If[Length[l1] != Length[l2],"Error in length", {l1[[#]], l2[[#]]} & /@ Range[1, Length[l1]]]

list1 = Reverse[Range[1, 9]]
Out[1]= {9, 8, 7, 6, 5, 4, 3, 2, 1}

list1 = Range[1, 9]
Out[2]= {1, 2, 3, 4, 5, 6, 7, 8, 9}


In[262]= list//TableForm
`