I have two lists. One with three levels (list) and a second one (list 2)
list = {{{2, 0}, {2, 3}},
{{5, 3}, {4, 0}},
{{0, 5}, {0, 0}}}
list2 = {1,2,3}
and I want to combine the pairs of each second level from list with list2 to get
listcombined = {{{1, 2, 0}, {1, 2, 3}},
{{2, 5, 3}, {2, 4, 0}},
{{3, 0, 5}, {3, 0, 0}}}
Right now I used Map Indexed
with the following function and got
combine [x_,index_]:={list2[[[index[1]]]],x}
MapIndexed [combine,list,{2}]
{{{{1, {2, 0}}, {1, {2, 3}}},
{{2, {5, 3}}, {2, {4, 0}}},
{{3, {0, 5}}, {3, {0, 0}}}}
To get the desired list I then use first Flatten
and two times Partition
.
Is there also an easier way, which avoids the last three steps?