pair lists to create tuples in order

后端 未结 7 1887
不知归路
不知归路 2020-12-29 03:41

I\'d like to combine two lists. If I have the following two lists: {a,b,c,d} and {1,2,3,4} what do I need to do so that I get {{a,1}, {b,2},

7条回答
  •  猫巷女王i
    2020-12-29 03:51

    An esoteric method is Flatten, which (from the Help Section on Flatten) also allows Transpose of a 'ragged' array.

    Flatten[ {{a, b, c, d}, {1, 2, 3, 4, 5}}, {{2}, {1}}]
    

    Out[6]= {{a, 1}, {b, 2}, {c, 3}, {d, 4}, {5}}

提交回复
热议问题