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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:46:44+00:00 2026-05-20T05:46:44+00:00

The general point of the program is to search for words and make sure

  • 0

The general point of the program is to search for words and make sure that they occur in the right order.

I am currently using the code

while not corpus[index_F2-1] == corpus[index_B]:
    index_F2 = corpus.index(corpus[index_F2], index_F2+1) 

in order to search for a word, check to make sure that a given word appears before it, and find a different instance of the same word in the corpus if the word does not appear in the correct environment. The only problem with this code is that, if the conditions are never met, it returns an error. Rather than having it return an error, it would be better if it could exit the loop, and then assign a new value to “F2” in order to try again. The obvious way to make the program exit the loop would be to use a while loop, but I am unsure how to get a while loop to not find a new value for F2 if the current one works. In short, it would work best if the script ran in this order.

  1. Check to see if the current F2 will ever work
  2. If it will not work, assign a new value to F2.
  3. Check again recurse and check to see if the new F2 will work
  4. and so on

An if statement would probably be in order, but exactly where and how it would work, I am unsure. Also, the code for reassigning F2 already exists. It is

index_E2= corpus.index(corpus[index_E2], index_E2+1)

index_F = index_E2+1

index_F2 = corpus.index(corpus[index_F], index_F+1)

A future problem that could present itself is that the corpus may run out of F2 values ( as a result of running out of E2 values) and display a similar error, but that is another issue.

  • 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-05-20T05:46:45+00:00Added an answer on May 20, 2026 at 5:46 am

    I think I might understand what you’re looking for. It sounds like you want to have multiple nested loops, with an exit point within the innermost loop. The most obvious way to achieve this, in my mind, is to enclose the loops within a function. Since all this corpus stuff is confusing, I’ll use a simple example:

    words_to_find = ['tree', 'cow', 'lots_of_other_words']
    words_to_search = ['bathtub', 'more_words']
    def find_words(words_to_search, words_to_find):
        for i, fword in enumerate(words_to_find):
            for j, sword in enumerate(words_to_search):
                if fword == sword: 
                    return (fword, i, j)
    

    You can nest as many loops as you like here — for, while, whatever — and still break out of all of them easily once you’ve found what you want.

    Let me know if that doesn’t answer your question.


    EDIT: I suppose if you wanted to have it all in one while loop you could do this:

    word_list = ['blah', 'blah2', 'etc']
    word_list2 = ['other', 'words']
    i = 0
    j = 0
    while True:
        if i == len(word_list):
            i = 0
            j += 1
        elif thing_I_want(word_list[i], word_list2[j]):
            do_something()
            break
        else:
            i += 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am currently writing a part of a program that takes user text
I have to make a program that sorts a collection of songs by runtime.
Take this code: using System; namespace OddThrow { class Program { static void Main(string[]
Can anyone point me to any guides, howto's or general documentation on how to
I'd like my associative array indexed by Point (or, in general, an Object )
general question is i like to build logger class that writes to single log
I need to write a program (a project for university) that solves (approx) an
I basically have a simple problem in my program that I just want to
Not a terribly good question, sorry. I have a program that needs to be
I am working on a program which includes a general purpose engine, some program

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.