Using Mathematica Gather/Collect properly
问题 How do I use Mathematica's Gather/Collect/Transpose functions to convert: { { {1, foo1}, {2, foo2}, {3, foo3} }, { {1, bar1}, {2, bar2}, {3, bar3} } } to { {1, foo1, bar1}, {2, foo2, bar2}, {3, foo3, bar3} } EDIT: Thanks! I was hoping there was a simple way, but I guess not! 回答1: Here is your list: tst = {{{1, foo1}, {2, foo2}, {3, foo3}}, {{1, bar1}, {2, bar2}, {3, bar3}}} Here is one way: In[84]:= Flatten/@Transpose[{#[[All,1,1]],#[[All,All,2]]}]&@ GatherBy[Flatten[tst,1],First] Out[84]= {