1
$\begingroup$

If I have two lists such as:

list1={60,65,70,75,80,85,87}

list2= {4.14166, 4.15138, 3.22417, 2.9524, -0.188672, 0.0653777, -0.63967}

How can I combine the two list to get a list like

list3={{value1list1,value1list2},{value2list1,value2list2},{value3list1,value3list2}....etc}

or with numbers

list3={{60,4.14166},{70, 4.15138},{75,3.22417}....etc}

$\endgroup$
4
  • 5
    $\begingroup$ Transpose[{list1, list2}] $\endgroup$ Commented Dec 21, 2020 at 2:10
  • 5
    $\begingroup$ Thread[{list1,list2}] $\endgroup$
    – cvgmt
    Commented Dec 21, 2020 at 2:12
  • 1
    $\begingroup$ thank you both. they work great ! $\endgroup$
    – John
    Commented Dec 21, 2020 at 2:13
  • 1
    $\begingroup$ Flatten[{list1,list2},{{2}}] probably also deserves a mention, a possible advantage being that it works with 'ragged' lists. (see here ) $\endgroup$
    – user1066
    Commented Dec 21, 2020 at 9:28

1 Answer 1

2
$\begingroup$

Here are a couple of more ways, in addition to the methods mentioned in the comments:

1. Using MapThread

   In[115]:= MapThread[{#1, #2} &, {list1, list2}]

   Out[115]= {{60, 4.14166}, {65, 4.15138}, {70, 3.22417}, {75, 2.9524}, {80, -0.188672}, {85, 0.0653777}, {87, -0.63967}}

2. Using Map and Lenght of the list

   In[116]:= {list1[[#]], list2[[#]]} & /@ Range[Length[list1]]

   Out[116]= {{60, 4.14166}, {65, 4.15138}, {70, 3.22417}, {75, 2.9524}, {80, -0.188672}, {85, 0.0653777}, {87, -0.63967}}
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.