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

  • Home
  • SEARCH
  • 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 8783239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:46:42+00:00 2026-06-13T20:46:42+00:00

I have a list of search items: search = (EPP3424, EPP5423, EPP4567, Continues… )

  • 0

I have a list of search items:

search = ("EPP3424", "EPP5423", "EPP4567", Continues... )

I want to check each row of a csv file where each row looks like this:

("1206502", "EPP5423", "97334343")
next row...

If any of the items in the search list appear in the row of the csv, add that entire row to a new list.

Problem is I can get it to only match one results, I can’t seem to get it to loop over the items correctly.

csvFile = open(fRoot + "\\SearchEPP.csv", 'r')
try:
    csvReader = csv.reader(csvFile)
    for row in csvReader:
        if all(s in row for s in search):
            print "Match"
            allEPP.append(row)
        else:
            print "no match"
finally:
    csvFile.close()

Python 2.6, Windows 7

UPDATE:

Here’s what I tried doing based on your response, still only returns one record.

f = open(fRoot + "\\EPP.txt", "r")

search = list()
for row in f:
    search.append(row)

search = set(search)   

#search = ("EPP2383", "EPP2384")

allEPP = list()

csvFile = open(fRoot + "\\SearchEPP.csv", 'r')
try:
    csvReader = csv.reader(csvFile)
    for row in csvReader:
        if any(r in search for r in row):
            print "Match"
            allEPP.append(row)
        else:
            print "."
finally:
    csvFile.close()
  • 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-13T20:46:43+00:00Added an answer on June 13, 2026 at 8:46 pm
    if all(s in row for s in search):
    

    should probably be:

    if any(s in row for s in search):
    

    Note that a better way to do this would be to convert search to a set once:

    search = set(search)
    ...
    

    And then do your check on the set (instead of the tuple). Membership tests for set are typically O(1) whereas they’re O(n) for tuples.

    if any(r in search for r in row):
    

    Or even:

    if search.intersection(row):
       ...
    

    Although the any solution might be faster (depending on how big row is and what the overhead of creating a new set via intersection is versus the overhead of a generator expression).


    As suggested by @RocketDonkey, you probably have newlines in your “search” list which is still causing you problems in your updated code. Here’s one fix:

    with open(fRoot + "\\EPP.txt", "r") as f:
        search = set(line.rstrip('\n') for line in f)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list with numerous Items. I want to search for a term
I have a list containing about 1000 file names to search under a directory
I have list and I need to search for items something like: if the
I have a list of items that are each associated with a start and
I have a list in sharepoint. I want to search across all the columns
I'm new to sencha touch. I have a list-search example. Now I want to
I have a list view full of items that contain multiple widgets each such
i have a list view with a search bar, i want to sort the
I have an unsorted UL list displaying search results. I want the user to
I have a long list of short strings and I want to search for

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.