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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:55:42+00:00 2026-06-16T21:55:42+00:00

I have a database saved as a list of tuples, and every tuple has

  • 0

I have a database saved as a list of tuples, and every tuple has 4 elements. The first element is the book’s number, the second element is the book’s name, the third element is the book’s author, and the forth element is the book’s publishing year.

I need a function called findBook(L, keyword), that receives the books as a list of tuples, keyword as a string, and returns all the tuples of books that have keyword in them.
The tuple of the book should be like this:

(BookNumber, BookName, Author, YearPublished)

How to write a search engine that will help us find these certain books?

I’ve tried to start with this, but it isn’t working:

def findBook(L,keyword):

    for i in L:
        BookNumber=i[0]
        BookName=i[1]
        Author=i[2]
        YearPublished=i[3]
        i=(BookNumber,BookName,Author,YearPublished)

        if keyword == str(BookName) or keyword==BookNumber or keyword==str(Author) or keyword==str(YearPublished):
            return i

so if i have a harry potter book , and i enter the keyword : “harry” it should return all the whole tuple.

  • 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-16T21:55:43+00:00Added an answer on June 16, 2026 at 9:55 pm

    You could iterate over the entries that may have the keyword you’re looking for, grouping them into a list, that shall be returned by the end of the process:

    def findBook(L, keyword):
    
        books = list()
        for book in L:
    
            book = tuple(entry for entry in book)
            if [i for i in book if str(i).find(keyword) != -1]:
                books.append(book)
    
        return books
    
    L = [(2,"harry potter and the prisoner of azkaban ","J.K Rowling","1998"),
            (3,"harry potter and the half blood prince","J.K Rowling","2007"),
            (6,"Harry potter and deathly hallows","J.K Rowling","2010"),
            (8,"The secret","someone","2009")]
    
    print findBook(L, "harry")
    

    Output:

    [(2, 'harry potter and the prisoner of azkaban ', 'J.K Rowling', '1998'), (3, 'harry potter and the half blood prince', 'J.K Rowling', '2007')]
    

    Notice the third entry was not found because the keyword is “harry” and not “Harry”, to do insensitive case search, use:

    def findBook(L, keyword):
    
        books = list()
        keyword = keyword.tolower()
    
        for book in L:
    
            book = tuple(entry for entry in book)
            if [i for i in book if str(i).tolower().find(keyword) != -1]:
                books.append(book)
    
        return books
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a Visa card number saved in my database, is there a
I have a date converted to double value and saved in database. Now, I
I have saved an image path in database like so: C:\Users\3embed\Documents\Visual Studio 2010\Projects\HeritageWeb\HeritageWeb\Images\startbutton.png I
I have saved a dataset in the sql database in an xml column using
I have this strings saved in my mysql database in format like: /uploads/attachments/18/105/WordPress_3_Cookbook.pdf Now,
I have never saved and retrieved an image to and from the database before.
I have latitude and longitude saved inside a database. I have the bing map
I have a blob saved in my database (a text file). I can retrieve
I have following query and data saved in a MySQL database with a timestamp
using fconnect user have authenticated and i have saved their userid to my database.

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.