Matching Items in Lists - Python
<p>So I know how to match items in two lists, but what I am curious about is how to link the two matches. For example, I have a browser based app and am using Jinja2 as my template language. <br><br>My program pulls a list of PDF files which also have corresponding XML files. (The files are named similarly, i.e. foo.xml contains the data for foo.pdf) The list of PDF files is displayed on the page, and when the user clicks on the name of a file from the list of PDFs, that file's XML data, if it exists yet, would be displayed in a little pop-up. <br><br>So, I guess my question would be, how do I connect the dots and specify the correct xml file to be displayed since <code>col_list[0]</code> is not always going to be the same file?<br><br> Below is my code creating the list of pdf files:</p>

<pre><code> col_list = '&lt;li class="ui-widget-content"&gt;'.join('%s&lt;/li&gt;' % (os.path.splitext(filename)[0])
                     for filename in listfiles
                     if filename.endswith('.pdf')
                     )
</code></pre>

<p>Thanks!</p>

<p><strong>Edit:</strong>
<br><br>
I'm going to give a different example in hopes of being less confusing. <br><br>
List 'A' is an ever-changing list of PDF files (foo.pdf, bar.pdf, etc.)<br>
List 'B' is an ever-changing list of XML files named the same as list 'A' (foo.xml, bar.xml, etc)<br><br>I am looping over both lists, and creating variables for each list. If these lists were identical, I could simply call <code>list_b[0]</code> to get the xml data for the first file, which would also be the first PDF. But, since some PDFs do not have XML files yet, the order of the lists do not match up. Let's say <code>list_b[0]</code>  is <code>foo.xml</code> and <code>list_a[3]</code> is <code>foo.pdf</code> How can I tell Python that I want the XML data for <code>foo.pdf</code> when the order of the lists is ever-changing?<br><br>
Sorry for the confusion.</p>
