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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:12:53+00:00 2026-06-13T13:12:53+00:00

I’m working using Python. I have a query, with words. For example, query=[hello, tree,

  • 0

I’m working using Python.

I have a query, with words. For example, query=[hello, tree, blue]

I’ve selected for each word in which documents it is, so I have a list for each word, where each position is one of the documents. Let’s say:

list_query[0]=[1,4,5]
list_query[1]=[5,8]
list_query[2]=[4,5,8]

So, I should get a result = [5]

But, I don’t wanna do it using intersection. I need to do it using iterations, i, j.

hello:
      i
      |
      1    4    5
tree:
      5    8
      |
      j

I’ll have to start with i=0, compare if the list_query[0][i]==list_query[1][j], if so add that number to the list. If not I should iterate the smaller number of boths iterators, and so on, with the result of that intersection of those lists and the rest of the elements of the query. But kind find how to do it and it’s driving me mad.

So if anyone could help me…
Thanks in advance.

  • 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-13T13:12:55+00:00Added an answer on June 13, 2026 at 1:12 pm

    I feel that you’re already pretty far along. I could show you an implementation, but you’ve described the algorithm already, so implementing it yourself shouldn’t be hard. But perhaps you don’t feel confident in your description.

    Let me restate your description in a slow and precise way, leaving out the information we don’t need about queries and such. We have two pre-sorted lists, and we want to find their intersection. Adapting your diagram with a slightly fuller example, starting with list a = [1, 4, 5, 7, 8], b = [5, 8, 9], i=0, and j=0, as well as an empty output list out = [] which I’ll leave out of the diagram initially…

    i = 0
    a = 1 4 5 7 8
    
    j = 0
    b = 5 8 9
    

    First we check if they’re equal. They aren’t, so we take the minimum of a[i] and b[j]. In this case, a[i] == 1 and b[j] == 5, so we want to increment i.

    i =   1
    a = 1 4 5 7 8
    
    j = 0
    b = 5 8 9
    

    Going through the same steps, we increment i again:

    i =     2
    a = 1 4 5 7 8
    
    j = 0
    b = 5 8 9
    

    Now things go differently; a[i] and b[j] are the same, so we want to append that value to the output list and increment both values:

    i =       3
    a = 1 4 5 7 8
    
    j =   1
    b = 5 8 9
    
    out = 5
    

    Now we continue. a[i] is again less than b[j]…

    i =         4
    a = 1 4 5 7 8
    
    j =   1
    b = 5 8 9
    

    And the values are the same, so we add that value to out and increment i and j…

    i =           5
    a = 1 4 5 7 8
    
    j =     2
    b = 5 8 9
    
    out = 5 8
    

    But now we find that i == len(a). So we know the algorithm has terminated.

    Now we have all we need to establish what variables we need and how the logic should work. We need list a, list b, index i, index j, and list out. We want to create a loop that stops when either i == len(a) or j == len(b), and within that loop, we want to test a[i] for equality with b[j]. If they are equal, we increment both i and j and append a[i] to out. If they are not equal, then we test whether a[i] < b[j]. If it is, then we increment i; otherwise, we increment j.

    This determines the intersection between two lists; now we just have to apply this to the first and the second list, and then apply the result to the third list, and then apply the result of that to the fourth, and so on.

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

Sidebar

Related Questions

I have an autohotkey script which looks up a word in a bilingual dictionary
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.