Help With Homework 4.6

I shouldn't have waited this long to seek help on this but better late than never right? Here is my problem: In the previous version of add_to_index procedure, we were checking to see if a keyword being added marches the on in the index and then if that is true, add the url. Now, am a little unsure of the problem in 4.6. Am I checking to see if the url is already there and if so, do not add it and if not so, add it? I know I need to modify the existing code. Which lines should remain intact? Should I still check the keyword marching and then check the url existence? Any hints will really help! Thanks.

asked 20 Mar '12, 17:18

Eenvincible's gravatar image

Eenvincible
3.6k164179
accept rate: 10%


8 Answers:

First examine what add_ to_ index() does before you modify.
Make sure it is clear for you before any change.
Understand the requirement.

Now to work:
We check if the keyword exists in the list. If not then append the new keyword and url to the list.
If the keyword is in list then we do not need to append the keyword, we do need to append the url.

So now this is the modification:
We want to check if the url (that belongs to the existing keyword in index) is not duplicated, so we have to check in a list of list ['< keyword >',[< url >' ....,'< url >']] if there are duplicate url's. We compare the input url with the url's sored in the list of list, if it exists we do not append that url.

link

answered 20 Mar '12, 17:51

iDev's gravatar image

iDev
1.3k62354

Thanks again for your hints. As I indicated earlier, I think I figured it out and am going to mark it as complete, all I wanted after that was the test cases. Thanks a bunch!

(20 Mar '12, 17:54) Eenvincible Eenvincible's gravatar image

Hey there, better late than never.

The HW asks you to

Modify add_to_index so that a given
url is only included once in the url
list for a keyword, no matter how many
times that keyword appears.

So, where before when we added a keyword, we might get duplicate URLs in list that is returned because we never looked to see if the url we are adding is already associated with that keyword. You might play with the original code to see that happen. Now you want to change it so that the url just appears once for that keyword.

So yea, if you found the keyword, is the url already in that list? What will you do if is it?

link

answered 20 Mar '12, 17:26

zyrcster-4's gravatar image

zyrcster-4
1.8k1332

This is so clear, Let me attempt this and let you know. Thanks.

(20 Mar '12, 17:28) Eenvincible Eenvincible's gravatar image

http://www.udacity-forums.com/cs101/questions/38276/homework-47-test-cases these test cases will work for 4.6 too..just avoid calling record_user_click() proc

link

answered 20 Mar '12, 17:55

sudha%20parthasarathy's gravatar image

sudha partha...
11.1k83176

You need to make sure that for every keyword, each URL is present at most once, i.e. no keyword has the same URL twice. You need to achieve this by changing the procedure that adds a url to a keyword.

link

answered 20 Mar '12, 17:22

Anton%20Golov's gravatar image

Anton Golov ♦
13.3k2174174

Am I checking to see if the url is already there and if so, do not add it and if not so, add it? Yes! Exactly what to do is probably too much help, but you do need to change the code in add_to_index.

(20 Mar '12, 17:24) wobbly-1 wobbly-1's gravatar image

In 4.6 U have to see if a given url is present in the index for that keyword. If its already there then you should not add it.

[[udacity,["http://www.udacity.com/cs101x/index.html","http://www.udacity.com/cs101x/index.html"]] if you see in the above case keyword "udacity" already has "http://www.udacity.com/cs101x/index.html" url so you should not add the same url again.

link

answered 20 Mar '12, 17:25

sudha%20parthasarathy's gravatar image

sudha partha...
11.1k83176

In other words, I should check to see if the keywords march then see again if the url already exists? I am sorry if it sounds stupid!

(20 Mar '12, 17:27) Eenvincible Eenvincible's gravatar image

Yep you are in the right track...

(20 Mar '12, 17:29) sudha partha... sudha%20parthasarathy's gravatar image

Just had another thought on this: when am checking the occurrence of the url, should I iterate through a single entry[1] or just the whole index?

(20 Mar '12, 17:32) Eenvincible Eenvincible's gravatar image

the question asks you to avoid duplicate url. I cannot give out the answer..am sorry...so think which to iterate...

(20 Mar '12, 17:44) sudha partha... sudha%20parthasarathy's gravatar image

I have solved it, thank you. I didn't want a direct answer either.

(20 Mar '12, 17:51) Eenvincible Eenvincible's gravatar image

Let me try that @jesyspa and then update you before it is too late here.

link

answered 20 Mar '12, 17:26

Eenvincible's gravatar image

Eenvincible
3.6k164179

First, thanks to you all guys. I think I have figured this problem out with your support, however, I need some test cases for the procedure in question! If you have any of that, help by posting them here so I can check them and make sure I have them right.

link

answered 20 Mar '12, 17:39

Eenvincible's gravatar image

Eenvincible
3.6k164179

I think the key to this problem is to create a nest set of for loops which first look through the keywords, then look through the urls. If the keyword and the url match, you can return out of the procedure without changing anything. If a match is not found you need to either add the keyword and the url or add the url to the existing keyword, using the append operation in either case.

link

answered 20 Mar '12, 17:44

Jared%20Hayter-3's gravatar image

Jared Hayter-3
10929

I am sure I have done that and it should be fine. I just wanted to be double sure by using test cases. Do you have any?

(20 Mar '12, 17:46) Eenvincible Eenvincible's gravatar image
Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,308
×1,718
×323
×41
×27

Asked: 20 Mar '12, 17:18

Seen: 291 times

Last updated: 20 Mar '12, 17:58