title: How to traverse and match multiple 2d arrays between folders with no repetition? (python)
body: <p>Say I have 3 folders and each has multiple files that contains strings inside them.</p>
  <p>I would like to do a complete matching of the files between each pair of folders (not within 1 folder) without repetition. The purpose of this matching algorithm is for some processing that follows after but it is not important at the moment here (if you really need to know, you can just treat it as a concatenate function of two long strings).</p>
  <p>For example, let f[i][j] be the 2d array where <em>i</em> represents the number of folders (<em>i</em> = 0,1,2 in this case) and <em>j</em> is the number of files inside each <em>i</em> folder.</p>
  <p>It is not necessary that the number of files in each folder is equal to the rest of the folders. i.e. folder 1 can have 5 files while folder 2 can have 3 files.</p>
  <p>For simplicity, let's define the arrays like this and since n=[1,3]:</p>
  <p>f[1][j] --&gt; where <em>j</em> has range 0 to 2 (meaning folder 1 has 3 files)</p>
  <p>f[2][j] --&gt; where <em>j</em> has range 0 to 1 (meaning folder 2 has 2 files)</p>
  <p>f[3][j] --&gt; where <em>j</em> has range 0 (meaning folder 3 has 1 files)</p>
  <p><strong>Question: How do I construct a matching algorithm to do this?</strong></p>
  <ul>
  <li>Match each file in f[n][ ] with each file in f[m][ ] with no repetition (i.e. if (f[n][j], f[m][j]) has already matched, there is no need to match f[m][j] with f[n][j] again)</li>
  <li>and <em>n</em> != <em>m</em> (i.e. don't match within 1 folder but match between different folders). You can assume all folders present in the directory path will be different.</li>
  </ul>
  <p>In this example, the match order for the 3 folders defined earlier should ideally be executed similar to these sequences below:</p>
  <p>======== Matching folder 1 and folder 2 ========</p>
  <ol>
  <li>f[1][0] match with f[2][0]</li>
  <li>f[1][0] match with f[2][1]</li>
  <li>f[1][1] match with f[2][0]</li>
  <li>f[1][1] match with f[2][1]</li>
  <li>f[1][2] match with f[2][0]</li>
  <li>f[1][2] match with f[2][1]</li>
  </ol>
  <p>======== Matching folder 1 and folder 3 ========</p>
  <ol start="7">
  <li>f[1][0] match with f[3][0]</li>
  <li>f[1][1] match with f[3][0]</li>
  <li>f[1][2] match with f[3][0]</li>
  </ol>
  <p>======== Matching folder 2 and folder 3 ========</p>
  <ol start="10">
  <li>f[2][0] match with f[3][0]</li>
  <li>f[2][1] match with f[3][0]</li>
  </ol>
  <p>How should I write this into code and what is the best way to do this (in terms of speed)? I have tried searching through StackOverflow but most of the questions tackle how to traverse only one 2d array. This question is more on, traversing two 2d arrays at the same time and also implementing combinations with no repetition matching. Of course, the algorithm should work regardless of the number of folders and number of files in each folder. How should I do this?</p>
  <p>Thanks!</p>