I have two lists {a, b, c, d, e} and {1, 2, 3, 4, 5}. I want to creat a new list of tuples as follows {{a, 1}, {b, 2}, {c, 3}, {d, 4}, {e, 5}}. Is there a command in Mathematica that allows me to do this?
Asked
Active
Viewed 356 times
1
m_goldberg
- 107,779
- 16
- 103
- 257
user40931
- 13
- 2
1 Answers
5
list1 = {a, b, c, d, e};
list2 = {1, 2, 3, 4, 5};
list = Thread@{list1, list2}
{{a, 1}, {b, 2}, {c, 3}, {d, 4}, {e, 5}}
-
As Kuba states:
x = {a,b,c,d,e}; y = {1,2,3,4,5}; Transpose[{x,y}]. – David G. Stork Jun 12 '16 at 00:06
Transpose. – Kuba Jun 11 '16 at 20:48(Transpose@# == Thread@# == Flatten[#, {{2}}] == MapThread[List, #] == Inner[List, Sequence @@ #, List]) &@{list1, list2}=> True. Note that Flatten will work with 'ragged' arrays. – user1066 Jun 12 '16 at 07:37