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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:20:07+00:00 2026-06-18T17:20:07+00:00

Having trouble finding a python solution to matching elements of one list against elements

  • 0

Having trouble finding a python solution to matching elements of one list against elements in another list without a whole pile of “for” and “if” loops. I’m hoping to find a better way to do this. I have some big iterating loops that go through multiple lists to perform matches. On a match, I want elements of the list removed. Here are two examples:

def score_and_retweet(auth):
    api = tweepy.API(auth)
    for tweet in api.home_timeline(count=100, include_rts=0):
        for goodword in tweet_whitelist:
            if goodword in tweet.text and tweet.retweet_count >= 2:
                try:
                    api.retweet(tweet.id_str)
                except tweepy.error.TweepError:
                    error_id = tweet.id_str

and

t = time.localtime()
    if t.tm_hour is 14 and (t.tm_wday is 1 or t.tm_wday is 4):
        htmlfiles = glob.glob(html_file_dir+'/*.html')
        for file in htmlfiles:
            for badword in filename_badwords:
                if badword in file:
                    try:
                        htmlfiles.remove(file)
                    except ValueError:
                        error = "already removed"
  • 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-18T17:20:08+00:00Added an answer on June 18, 2026 at 5:20 pm

    Not sure how much it would change in terms of performance, but you could write a filter function

    For example in the second case (if you’re looking for exact matches)

    def fileFilter(f):
        if f in filename_badwords:
            return False
        else:
            return True
    

    Then use:

    goodFiles = filter(fileFilter, htmlfiles)
    

    The advantage this has over set intersection is you can make the filter function as complex as you want (you have multiple conditions in your first example)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble finding the correct syntax for creating a Definition List via Perl to
I am having trouble finding a solution for this question. Suggest any solution for
I'm having trouble finding a solution to this problem. I have set up this
I'm having trouble finding a solution to this via google but I would have
I am having some trouble finding the solution for the Join all exercise in
Having trouble finding a solution for my situation here. Sorry if this has been
I've been having trouble finding this one. I have a div that is centered
I'm having trouble finding anything on the subject. Let's say I have a list
I am new to python and am having trouble finding the correct syntax to
I am having trouble finding one because Whitespace is a common word, but I'm

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.