# Help With Homework 4.6

 0 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 3.6k●16●41●79 accept rate: 10%

 0 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. answered 20 Mar '12, 17:51 iDev 1.3k●6●23●54 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
 2 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? answered 20 Mar '12, 17:26 zyrcster-4 1.8k●1●3●32 This is so clear, Let me attempt this and let you know. Thanks. (20 Mar '12, 17:28) Eenvincible
 1 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 answered 20 Mar '12, 17:55 sudha partha... 11.1k●8●31●76
 0 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. answered 20 Mar '12, 17:22 Anton Golov ♦ 13.3k●21●74●174 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
 0 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. answered 20 Mar '12, 17:25 sudha partha... 11.1k●8●31●76 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 Yep you are in the right track... (20 Mar '12, 17:29) sudha partha... 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 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... I have solved it, thank you. I didn't want a direct answer either. (20 Mar '12, 17:51) Eenvincible
 0 Let me try that @jesyspa and then update you before it is too late here. answered 20 Mar '12, 17:26 Eenvincible 3.6k●16●41●79
 0 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. answered 20 Mar '12, 17:39 Eenvincible 3.6k●16●41●79 http://www.udacity-forums.com/cs101/questions/36288/homework-46-test-cases (20 Mar '12, 17:58) zyrcster-4
 0 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. answered 20 Mar '12, 17:44 Jared Hayter-3 109●2●9 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
Question text:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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

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