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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:40:28+00:00 2026-06-12T06:40:28+00:00

index = {‘Michael’: [[‘mj.com’,1], [‘Nine.com’,9],[‘i.com’, 34]], / ‘Jackson’: [[‘One.com’,4],[‘mj.com’, 2],[‘Nine.com’, 10], [‘i.com’, 45]], /

  • 0
index = {'Michael': [['mj.com',1], ['Nine.com',9],['i.com', 34]], / 
         'Jackson': [['One.com',4],['mj.com', 2],['Nine.com', 10], ['i.com', 45]], /
         'Thriller' : [['Seven.com', 7], ['Ten.com',10], ['One.com', 5], ['mj.com',3]}

# In this dictionary (index), for eg: 'KEYWORD': 
# [['THE LINK in which KEYWORD is present,'POSITION
# of KEYWORD in the page specified by link']]

eg: Michael is present in MJ.com, NINE.com, and i.com at positions 1, 9, 34 of respective pages.

Please help me with a python procedure which takes index and KEYWORDS as input.

When i enter 'MICHAEL'. The result should be:

>>['mj.com', 'nine.com', 'i.com']

When I enter 'MICHAEL JACKSON'. The result should be :

>>['mj.com', 'Nine.com']

as ‘Michael' and ‘Jackson' are present at 'mj.com' and 'nine.com' consecutively i.e. in positions (1,2) & (9,10) respectively. The result should not show 'i.com' even though it contains both KEYWORDS but they are not placed consecutively.

When I enter 'MICHAEL JACKSON THRILLER', the result should be

['mj.com']

as the 3 words 'MICHAEL', 'JACKSON', 'THRILLER' are placed consecutively in 'mj.com' ie positions (1, 2, 3) respectively.

If I enter 'THRILLER JACKSON' or 'THRILLER FEDERER', the result should be NONE.

  • 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-12T06:40:30+00:00Added an answer on June 12, 2026 at 6:40 am

    As a side note, Udacity Intro to CS covers precisely this question. This makes a number of assumptions about proper inputs (essentially that it never encounters any incorrect ones).

    def lookup(index,KEYWORDS):
        kw = KEYWORDS.split()
        if len(kw) == 1:
            return [site[0] for site in index[kw[0]]]
        else:
            positions = {}
            result = []
            kw = KEYWORDS.split()
            for kword in kw:
                for site in index[kword]:
                    positions[(kword,site[0])]=site[1]
            for i in range(0,len(kw)-1):
                cur_urls = [site[0] for site in index[kw[i]]]
                next_urls = [site[0] for site in index[kw[i+1]]]
                if i == 0:
                    result = cur_urls
                for url in cur_urls:
                    if url in next_urls:
                        if not (positions[kw[i+1],url]-positions[kw[i],url]) == 1:
                            result.remove(url)
                    else:
                        if url in result:
                            result.remove(url)
            return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

index = 5; alert($('ul li:eq(index) a',context).html()); This script will alert : Null , but
My index.jsp page, load my form with this line of code : $('#box').load('/Edit_Data.jsp?id=' +
Calling Index view is giving me this very very annoying error . Can anybody
On index.gsp I have this to redirect it to list.gsp so I'm imagining is
index.php contains links in this style: <a href=index.php?id=1>1</a> <a href=index.php?id=2>2</a> and then a PHP
index.php has this jquery code which loads notifications.inc.php into a div on the page
My index page have some records where each record have one or more images
Calling index.php?pConta=1&pDataInicial=01-01-2000&pDataFinal=31-12-2000 I get this notices: [08-Oct-2009 17:30:35] PHP Notice: Undefined index: pConta in
index.php session_start(); if(!isset($_GET['n'])) { $_SESSION['foo'] = bar; header(Location: /index.php?n=D); } echo FOO: .$_SESSION['foo']; This
In index.php theres a link where it makes a ajax request to show.php .

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.