Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:32:32+00:00 2026-06-15T01:32:32+00:00

So I know how to match items in two lists, but what I am

  • 0

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.

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.

So, I guess my question would be, how do I connect the dots and specify the correct xml file to be displayed since col_list[0] is not always going to be the same file?

Below is my code creating the list of pdf files:

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

Thanks!

Edit:

I’m going to give a different example in hopes of being less confusing.

List ‘A’ is an ever-changing list of PDF files (foo.pdf, bar.pdf, etc.)
List ‘B’ is an ever-changing list of XML files named the same as list ‘A’ (foo.xml, bar.xml, etc)

I am looping over both lists, and creating variables for each list. If these lists were identical, I could simply call list_b[0] 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 list_b[0] is foo.xml and list_a[3] is foo.pdf How can I tell Python that I want the XML data for foo.pdf when the order of the lists is ever-changing?

Sorry for the confusion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:32:33+00:00Added an answer on June 15, 2026 at 1:32 am

    If I understand correctly: you want to use a set for the XML filenames, and look them up:

    pdfs = ['a.pdf', 'b.pdf', 'c.pdf', 'd.pdf']
    xmls = ['a.xml', 'd.xml', 'b.xml']
    
    xml_set = set(xmls)
    
    result = []
    for pdf in pdfs:
        xml = pdf.replace('.pdf', '.xml')
        if xml in xml_set:
            result.append('Matched %s to %s' % (pdf, xml))
        else:
            result.append("%s doesn't have a corresponding XML file" % (pdf,))
    
    print result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know what I'm doing wrong, I have two lists of items and
Say I have two lists or arrays of strings. For example: list 1: a,
Given a scenario where we have multiple lists of pairs of items, for example:
I know i can match numbers with Pattern.compile(\\d*); But it doesn't handle the long
I know that you can't repeat match groups in Lua. For example, if I
I know i can do something like ab[^c]+def which should match ab_blah_hi_blah_def but is
I'm building a little search application (I know I can use match against). But
I don't really know that much about bash scripts OR imagemagick, but I am
I know that there are similar questions to mine that have been answered, but
I would like to know how can I create a regexp to match the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.