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 8415417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:26:28+00:00 2026-06-10T01:26:28+00:00

I have a list of strings and if the string in my list appears

  • 0

I have a list of strings and if the string in my list appears in the filename then I want python to open the file. The catch is, I want python to open the files in the order the string appears in my list. My current code opens the files in the order python wants and only checks if the string in the list appears in the filename.

files

dogs.html
cats.html
fish.html

python

list = ['fi', 'do', 'ca']
for name in glob.glob('*.html'):
  for item in list:
    if item in name:
      with open(name) as k:
  • 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-10T01:26:30+00:00Added an answer on June 10, 2026 at 1:26 am
    lis = ['fi', 'do', 'ca']
    
    for item in lis:
       for name in glob.glob('*.html'):
          if item in name:
             with open(name) as k:
    

    or create a list of all files first, and then filter that list with every iteration of list:

    >>> names=glob.glob('*.html')
    >>> lis=['fi','do','ca']
    >>> for item in lis:
    ...    for name in filter(lambda x:item in x,names):
    ...         with open('name') as k:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which utilises Guava's Files.readLines() method: List<String> strings = Lists.newArrayList();
I have this List<string> . How to get certain strings via LINQ? I guessed
E.G. to create an ArrayList of Strings we have to do something like List<String>
I have a list of string values that I want add to a hashtable
Suppose I have a list of strings where each string is exactly 4 characters
If I have 2 lists of strings: List<string> firstList = new List<string>(010, 111, 123);
I have a list of strings like this: ['Aden', 'abel'] I want to sort
I have List[(String,String)] and I need to sort them by the 2nd value and
I have list of strings like this FirstName-Lastname (separated by a dash -) I
I have a List of Strings. EXAMPLE_1, EXAMPLE_2, EXAMPLE_3 ... EXAMPLE_99 What is 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.