Python append to label from multiple lists
<p>So I have several lists that are the headers of variables in a data file. The setup looks like this:</p>

<blockquote>
<pre><code>headerGroup1 = ["1", "2", "3, "4", "5"]
headerGroup2 = ["6", "7", "8, "9", "10"]
headerGroup3 = ["1", "2", "3", "4", "5"]
</code></pre>
</blockquote>

<p>And I have a master file that looks like this:</p>

<blockquote>
<pre><code>masterVars = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
</code></pre>
</blockquote>

<p>I want to do three things:</p>

<ul>
<li>Create a list that includes all the items from masterVars in order. And I don't know if values are unique.</li>
<li>If a list item contained in headerGroupX is in the masterVars, prepend that header group to the list item. </li>
<li>Dump a list that contains all 64k items into something I can manage in SPSS (sort of kidding about this one)</li>
</ul>

<p>I think this would be simple if there were only 2 lists. The big problem I think I'm running into is what happens after you prepend data to a list item. But I'm not totally sure what I'm messing up.</p>

<p>EDITED:</p>

<p>Here is an example of what I would want to output:</p>

<blockquote>
<pre><code>newMasterFile = ["headerGroup1, headerGroup3, 1", "headerGroup1, headerGroup3, 2", etc.]
</code></pre>
</blockquote>

<p>Does this make anything clearer?</p>
