# Now that HW 4 is closed, can someone explain 4.7 PLEASE??

 1 1 I have an idea how the record_user_click should work, but I'm still hung up on trying to make sure the index structure is correct in the first place. Would someone be so kind as to help me with this part, please? asked 20 Mar '12, 20:06 Chris Allan 305●2●10●23 accept rate: 0%

 4 def record_user_click(index,keyword,url): for entry in index: if entry[0]==keyword: for e in entry[1]: if e[0]==url: e[1]=e[1]+1  and def add_to_index(index, keyword, url): for entry in index: if entry[0] == keyword: entry[1].append([url,0]) return # not found, add new keyword to index index.append([keyword,[[url,0]]])  answered 20 Mar '12, 20:11 Tom Vandenbosch 6.7k●39●82●132 Thank you so much! :D I wasn't adding the extra set of [ ] around url,0 which caused me to have problems. (20 Mar '12, 20:14) Chris Allan Interesting, I also forgot to add them initially, but then I got an error with some tests. (20 Mar '12, 20:17) Tom Vandenbosch I've been banging my head against the wall for 3 days because in my head, I knew how I wanted the structure to be, but was having a problem writing it in Python code. (20 Mar '12, 20:19) Chris Allan In a way, you should get at least 60% of the marks for such an answer. But yes, a grading bot is a grading bot. (20 Mar '12, 20:22) Tom Vandenbosch Kinda reminds me of my 7th grade math teacher in that aspect, then.. LOL (20 Mar '12, 20:30) Chris Allan LOL - and thanks for being so generous with karma @atomicxblue (20 Mar '12, 20:32) Tom Vandenbosch You're quite welcome! You helped me so, I felt I should return the favor. (20 Mar '12, 21:38) Chris Allan
 1 Tom's answer is the same as mine, be sure to watch the solution video (click Next on 4.7) if this still doesn't make sense. answered 20 Mar '12, 20:13 zyrcster-4 1.8k●1●3●32
 0 one of the possible ways to implement an index structure is as in hw4.1: [ [ keyword, [ [url, count], [url, count], … ] ], … ] answered 20 Mar '12, 20:10 Evaldas 167●3●6
 0 Just a slight variation to avoid duplication of key words & urls in the index: def record_user_click(index,keyword,url): for e in index: if e[0] == keyword: for x in e[1]: if x[0] == url: x[1] = x[1] + 1 return index def add_to_index(index, keyword, url): exclude = True for entry in index: count = 0 if entry[0] == keyword: exclude = False for x in entry [1]: if x[0] == url: count = count + 1 if count == 0: entry[1].append([url,0]) return if exclude: index.append([keyword, [[url,0]]])  answered 20 Mar '12, 20:34 Arvind Deogi... 657●1●7●27
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,212
×60