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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:41:18+00:00 2026-06-04T21:41:18+00:00

I have been tasked with creating a binary search over a list of words,

  • 0

I have been tasked with creating a binary search over a list of words, I have come up with 2 implementations (and clearly haven’t put in a case where the word isn’t found yet but that’s not an issue yet), however when the list is narrowed down to the word I am looking for, my function does not finish, instead it keeps running until maximum recursive depth is exceeded.

I put in print and it clearly shows the word at dasList[mid], and shows this over and over again until it finally gives up.

def _bisect2(dasList, word):
    mid = int(len(dasList)/2)
    if word.lower() > dasList[mid].lower():
        return _bisect2(dasList[mid: len(dasList)], word)            
    if word.lower() < dasList[mid].lower():
        return _bisect2(dasList[0: mid], word)
    else:
        return mid

this is being called by

print(_bisect2(fileList, input('Please type a word')))

I am using the Python 3.0 interpretor. Any suggestions?

  • 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-04T21:41:19+00:00Added an answer on June 4, 2026 at 9:41 pm

    Your implementation (almost) works for me (and doesn’t show the behavior you described with my pre-sorted input). I assume you’ve sorted your input files? A slightly modified (working) example is posted below.

    def _bisect2(dasList, word,lidx=0):
        mid = int(len(dasList)/2)
        if word.lower() > dasList[mid].lower():
            return _bisect2(dasList[mid:], word,lidx=lidx+mid)            
        elif word.lower() < dasList[mid].lower():
            return _bisect2(dasList[:mid], word,lidx=lidx)
        return lidx+mid
    
    words=sorted(["one","two","three","four","five","twenty","foo"])
    print (words)
    print (_bisect2(words,'three'))
    

    Note that you were returning the index in the last partial list (which will always be 0)…

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

Sidebar

Related Questions

I have been tasked with creating a site wide search feature. The search needs
I have been tasked with creating a Software Installation Approval section for our Intranet.
I have been tasked with creating an API for retrieving and adding content to
I have been tasked with creating an application for a company to store current
Hello I have been tasked with creating a fairly complex web application in php,
I am new to WIX and have been tasked with creating an installer that
I have been tasked with the job of creating a web based system to
I've been tasked with creating a list of all possibilities using data in 8
Recently I have been tasked with creating an application for a business that basically
I've been tasked with creating an IM app for IOS. I currently have an

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.