1
$\begingroup$

Suppose I have $n$ lists, How to combine those $n$ lists without specifying whole $n$ sets?

I mean; For a given lists

list1={{3, 1, 1}, {1, 3, 1}, {1, 1, 3}} list2={{2, 2, 1}, {2, 1, 2}, {1, 2, 2}}

Using the command Flatten, I can do

 Flatten[{lists1,lists2},1]

Produces what I want. i.e.,

{{3, 1, 1}, {1, 3, 1}, {1, 1, 3}, {2, 2, 1}, {2, 1, 2}, {1, 2, 2}}

For the next cases, I do the similar way. But I want to do this more general. For example given $list[1], \cdots, list[n]$ without specifiying all $n$ elements as

  Flatten[{list[1], list[2], .... ,list[n]},1]

Is there another way to implement the same operation?

$\endgroup$
2
  • $\begingroup$ list1, list2 or list[1] , list[2] ? Why not Join and Flatten at level 1? $\endgroup$
    – Syed
    Dec 24, 2021 at 12:39
  • $\begingroup$ Maybe Flatten[Table[Symbol["list" <> IntegerString[i]], {i, 1, 2}]] ? $\endgroup$
    – user1066
    Dec 24, 2021 at 12:57

2 Answers 2

2
$\begingroup$

From @user1066, I realize this works fine

   Flatten[Table[list[i], {i, 1, n}],1] 
$\endgroup$
1
  • $\begingroup$ In the case you consider ( and I think I misunderstood your question), there is also Array[lst,10] $\endgroup$
    – user1066
    Dec 24, 2021 at 15:00
1
$\begingroup$
mylist[i_] := RandomInteger[i, {3, 3}]
Catenate[mylist /@ Range[5]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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